| 1 |
/* Definitions for GCC. Part of the machine description for CRIS. |
| 2 |
Copyright (C) 1998-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Axis Communications. Written by Hans-Peter Nilsson. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#define IN_TARGET_CODE 1 |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
#include "system.h" |
| 25 |
#include "coretypes.h" |
| 26 |
#include "backend.h" |
| 27 |
#include "target.h" |
| 28 |
#include "rtl.h" |
| 29 |
#include "tree.h" |
| 30 |
#include "stringpool.h" |
| 31 |
#include "attribs.h" |
| 32 |
#include "cfghooks.h" |
| 33 |
#include "df.h" |
| 34 |
#include "memmodel.h" |
| 35 |
#include "tm_p.h" |
| 36 |
#include "optabs.h" |
| 37 |
#include "regs.h" |
| 38 |
#include "emit-rtl.h" |
| 39 |
#include "recog.h" |
| 40 |
#include "cgraph.h" |
| 41 |
#include "diagnostic-core.h" |
| 42 |
#include "conditions.h" |
| 43 |
#include "insn-attr.h" |
| 44 |
#include "alias.h" |
| 45 |
#include "varasm.h" |
| 46 |
#include "stor-layout.h" |
| 47 |
#include "calls.h" |
| 48 |
#include "explow.h" |
| 49 |
#include "expr.h" |
| 50 |
#include "reload.h" |
| 51 |
#include "output.h" |
| 52 |
#include "tm-constrs.h" |
| 53 |
#include "builtins.h" |
| 54 |
#include "cfgrtl.h" |
| 55 |
#include "tree-pass.h" |
| 56 |
#include "opts.h" |
| 57 |
|
| 58 |
/* This file should be included last. */ |
| 59 |
#include "target-def.h" |
| 60 |
|
| 61 |
/* Usable when we have an amount to add or subtract, and want the |
| 62 |
optimal size of the insn. */ |
| 63 |
#define ADDITIVE_SIZE_MODIFIER(size) \ |
| 64 |
((size) <= 63 ? "q" : (size) <= 255 ? "u.b" : (size) <= 65535 ? "u.w" : ".d") |
| 65 |
|
| 66 |
#define LOSE_AND_RETURN(msgid, x) \ |
| 67 |
do \ |
| 68 |
{ \ |
| 69 |
cris_operand_lossage (msgid, x); \ |
| 70 |
return; \ |
| 71 |
} while (0) |
| 72 |
|
| 73 |
enum cris_retinsn_type |
| 74 |
{ CRIS_RETINSN_UNKNOWN = 0, CRIS_RETINSN_RET, CRIS_RETINSN_JUMP }; |
| 75 |
|
| 76 |
/* Per-function machine data. */ |
| 77 |
struct GTY(()) machine_function |
| 78 |
{ |
| 79 |
int needs_return_address_on_stack; |
| 80 |
|
| 81 |
/* This is the number of registers we save in the prologue due to |
| 82 |
stdarg. */ |
| 83 |
int stdarg_regs; |
| 84 |
|
| 85 |
enum cris_retinsn_type return_type; |
| 86 |
}; |
| 87 |
|
| 88 |
/* This little fix suppresses the 'u' or 's' when '%e' in assembly |
| 89 |
pattern. */ |
| 90 |
static char cris_output_insn_is_bound = 0; |
| 91 |
|
| 92 |
/* In code for output macros, this is how we know whether e.g. constant |
| 93 |
goes in code or in a static initializer. */ |
| 94 |
static int in_code = 0; |
| 95 |
|
| 96 |
static machine_mode cris_promote_function_mode (const_tree, machine_mode, |
| 97 |
int *, const_tree, int); |
| 98 |
|
| 99 |
static unsigned int cris_atomic_align_for_mode (machine_mode); |
| 100 |
|
| 101 |
static void cris_print_base (rtx, FILE *); |
| 102 |
|
| 103 |
static void cris_print_index (rtx, FILE *); |
| 104 |
|
| 105 |
static void cris_output_addr_const (FILE *, rtx); |
| 106 |
|
| 107 |
static struct machine_function * cris_init_machine_status (void); |
| 108 |
|
| 109 |
static rtx cris_struct_value_rtx (tree, int); |
| 110 |
|
| 111 |
static void cris_setup_incoming_varargs (cumulative_args_t, |
| 112 |
const function_arg_info &, |
| 113 |
int *, int); |
| 114 |
|
| 115 |
static int cris_initial_frame_pointer_offset (void); |
| 116 |
|
| 117 |
static void cris_operand_lossage (const char *, rtx); |
| 118 |
|
| 119 |
static int cris_reg_saved_in_regsave_area (unsigned int); |
| 120 |
|
| 121 |
static void cris_print_operand (FILE *, rtx, int); |
| 122 |
|
| 123 |
static void cris_print_operand_address (FILE *, machine_mode, rtx); |
| 124 |
|
| 125 |
static bool cris_print_operand_punct_valid_p (unsigned char code); |
| 126 |
|
| 127 |
static void cris_conditional_register_usage (void); |
| 128 |
|
| 129 |
static void cris_asm_output_mi_thunk |
| 130 |
(FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree); |
| 131 |
|
| 132 |
static void cris_file_start (void); |
| 133 |
static void cris_init_libfuncs (void); |
| 134 |
|
| 135 |
static unsigned int cris_postdbr_cmpelim (void); |
| 136 |
|
| 137 |
static reg_class_t cris_preferred_reload_class (rtx, reg_class_t); |
| 138 |
static reg_class_t cris_spill_class (reg_class_t, machine_mode); |
| 139 |
|
| 140 |
static int cris_register_move_cost (machine_mode, reg_class_t, reg_class_t); |
| 141 |
static int cris_memory_move_cost (machine_mode, reg_class_t, bool); |
| 142 |
static machine_mode cris_cc_modes_compatible (machine_mode, machine_mode); |
| 143 |
static bool cris_rtx_costs (rtx, machine_mode, int, int, int *, bool); |
| 144 |
static int cris_address_cost (rtx, machine_mode, addr_space_t, bool); |
| 145 |
static bool cris_pass_by_reference (cumulative_args_t, |
| 146 |
const function_arg_info &); |
| 147 |
static int cris_arg_partial_bytes (cumulative_args_t, |
| 148 |
const function_arg_info &); |
| 149 |
static rtx cris_function_arg (cumulative_args_t, const function_arg_info &); |
| 150 |
static rtx cris_function_incoming_arg (cumulative_args_t, |
| 151 |
const function_arg_info &); |
| 152 |
static void cris_function_arg_advance (cumulative_args_t, |
| 153 |
const function_arg_info &); |
| 154 |
static rtx_insn *cris_md_asm_adjust (vec<rtx> &, vec<rtx> &, |
| 155 |
vec<machine_mode> &, vec<const char *> &, |
| 156 |
vec<rtx> &, vec<rtx> &, |
| 157 |
HARD_REG_SET &, location_t); |
| 158 |
|
| 159 |
static void cris_option_override (void); |
| 160 |
static void cris_option_override_after_change (); |
| 161 |
|
| 162 |
static bool cris_frame_pointer_required (void); |
| 163 |
|
| 164 |
static void cris_asm_trampoline_template (FILE *); |
| 165 |
static void cris_trampoline_init (rtx, tree, rtx); |
| 166 |
|
| 167 |
static rtx cris_function_value(const_tree, const_tree, bool); |
| 168 |
static rtx cris_libcall_value (machine_mode, const_rtx); |
| 169 |
static bool cris_function_value_regno_p (const unsigned int); |
| 170 |
static unsigned int cris_hard_regno_nregs (unsigned int, machine_mode); |
| 171 |
static bool cris_hard_regno_mode_ok (unsigned int, machine_mode); |
| 172 |
static HOST_WIDE_INT cris_static_rtx_alignment (machine_mode); |
| 173 |
static HOST_WIDE_INT cris_constant_alignment (const_tree, HOST_WIDE_INT); |
| 174 |
static bool cris_legitimate_address_p_hook (machine_mode, rtx, bool, |
| 175 |
code_helper); |
| 176 |
|
| 177 |
/* This is the parsed result of the "-max-stack-stackframe=" option. If |
| 178 |
it (still) is zero, then there was no such option given. */ |
| 179 |
int cris_max_stackframe = 0; |
| 180 |
|
| 181 |
/* This is the parsed result of the "-march=" option, if given. */ |
| 182 |
int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION; |
| 183 |
|
| 184 |
#undef TARGET_ASM_ALIGNED_HI_OP |
| 185 |
#define TARGET_ASM_ALIGNED_HI_OP "\t.word\t" |
| 186 |
#undef TARGET_ASM_ALIGNED_SI_OP |
| 187 |
#define TARGET_ASM_ALIGNED_SI_OP "\t.dword\t" |
| 188 |
#undef TARGET_ASM_ALIGNED_DI_OP |
| 189 |
#define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t" |
| 190 |
|
| 191 |
/* We need to define these, since the 2byte, 4byte, 8byte op:s are only |
| 192 |
available in ELF. These "normal" pseudos do not have any alignment |
| 193 |
constraints or side-effects. */ |
| 194 |
#undef TARGET_ASM_UNALIGNED_HI_OP |
| 195 |
#define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP |
| 196 |
|
| 197 |
#undef TARGET_ASM_UNALIGNED_SI_OP |
| 198 |
#define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP |
| 199 |
|
| 200 |
#undef TARGET_ASM_UNALIGNED_DI_OP |
| 201 |
#define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP |
| 202 |
|
| 203 |
#undef TARGET_PRINT_OPERAND |
| 204 |
#define TARGET_PRINT_OPERAND cris_print_operand |
| 205 |
#undef TARGET_PRINT_OPERAND_ADDRESS |
| 206 |
#define TARGET_PRINT_OPERAND_ADDRESS cris_print_operand_address |
| 207 |
#undef TARGET_PRINT_OPERAND_PUNCT_VALID_P |
| 208 |
#define TARGET_PRINT_OPERAND_PUNCT_VALID_P cris_print_operand_punct_valid_p |
| 209 |
|
| 210 |
#undef TARGET_CONDITIONAL_REGISTER_USAGE |
| 211 |
#define TARGET_CONDITIONAL_REGISTER_USAGE cris_conditional_register_usage |
| 212 |
|
| 213 |
#undef TARGET_ASM_OUTPUT_MI_THUNK |
| 214 |
#define TARGET_ASM_OUTPUT_MI_THUNK cris_asm_output_mi_thunk |
| 215 |
#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
| 216 |
#define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall |
| 217 |
|
| 218 |
#undef TARGET_ASM_FILE_START |
| 219 |
#define TARGET_ASM_FILE_START cris_file_start |
| 220 |
|
| 221 |
#undef TARGET_INIT_LIBFUNCS |
| 222 |
#define TARGET_INIT_LIBFUNCS cris_init_libfuncs |
| 223 |
|
| 224 |
#undef TARGET_LEGITIMATE_ADDRESS_P |
| 225 |
#define TARGET_LEGITIMATE_ADDRESS_P cris_legitimate_address_p_hook |
| 226 |
|
| 227 |
#undef TARGET_PREFERRED_RELOAD_CLASS |
| 228 |
#define TARGET_PREFERRED_RELOAD_CLASS cris_preferred_reload_class |
| 229 |
|
| 230 |
#undef TARGET_SPILL_CLASS |
| 231 |
#define TARGET_SPILL_CLASS cris_spill_class |
| 232 |
|
| 233 |
/* We don't define TARGET_FIXED_CONDITION_CODE_REGS, as at the time of |
| 234 |
this writing, it has an effect only on pre-reload CSE and when |
| 235 |
scheduling (and for "macro fusion" at that). Neither applies for |
| 236 |
CRIS so don't waste compilation cycles on enabling a pass that does |
| 237 |
nothing. Beware of changes to its usage; it may make sense to enable |
| 238 |
"later". */ |
| 239 |
|
| 240 |
#undef TARGET_CC_MODES_COMPATIBLE |
| 241 |
#define TARGET_CC_MODES_COMPATIBLE cris_cc_modes_compatible |
| 242 |
|
| 243 |
#undef TARGET_FLAGS_REGNUM |
| 244 |
#define TARGET_FLAGS_REGNUM CRIS_CC0_REGNUM |
| 245 |
|
| 246 |
#undef TARGET_REGISTER_MOVE_COST |
| 247 |
#define TARGET_REGISTER_MOVE_COST cris_register_move_cost |
| 248 |
#undef TARGET_MEMORY_MOVE_COST |
| 249 |
#define TARGET_MEMORY_MOVE_COST cris_memory_move_cost |
| 250 |
#undef TARGET_RTX_COSTS |
| 251 |
#define TARGET_RTX_COSTS cris_rtx_costs |
| 252 |
#undef TARGET_ADDRESS_COST |
| 253 |
#define TARGET_ADDRESS_COST cris_address_cost |
| 254 |
|
| 255 |
#undef TARGET_PROMOTE_FUNCTION_MODE |
| 256 |
#define TARGET_PROMOTE_FUNCTION_MODE cris_promote_function_mode |
| 257 |
|
| 258 |
#undef TARGET_ATOMIC_ALIGN_FOR_MODE |
| 259 |
#define TARGET_ATOMIC_ALIGN_FOR_MODE cris_atomic_align_for_mode |
| 260 |
|
| 261 |
#undef TARGET_HAVE_SPECULATION_SAFE_VALUE |
| 262 |
#define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed |
| 263 |
|
| 264 |
#undef TARGET_STRUCT_VALUE_RTX |
| 265 |
#define TARGET_STRUCT_VALUE_RTX cris_struct_value_rtx |
| 266 |
#undef TARGET_SETUP_INCOMING_VARARGS |
| 267 |
#define TARGET_SETUP_INCOMING_VARARGS cris_setup_incoming_varargs |
| 268 |
#undef TARGET_PASS_BY_REFERENCE |
| 269 |
#define TARGET_PASS_BY_REFERENCE cris_pass_by_reference |
| 270 |
#undef TARGET_ARG_PARTIAL_BYTES |
| 271 |
#define TARGET_ARG_PARTIAL_BYTES cris_arg_partial_bytes |
| 272 |
#undef TARGET_FUNCTION_ARG |
| 273 |
#define TARGET_FUNCTION_ARG cris_function_arg |
| 274 |
#undef TARGET_FUNCTION_INCOMING_ARG |
| 275 |
#define TARGET_FUNCTION_INCOMING_ARG cris_function_incoming_arg |
| 276 |
#undef TARGET_FUNCTION_ARG_ADVANCE |
| 277 |
#define TARGET_FUNCTION_ARG_ADVANCE cris_function_arg_advance |
| 278 |
#undef TARGET_MD_ASM_ADJUST |
| 279 |
#define TARGET_MD_ASM_ADJUST cris_md_asm_adjust |
| 280 |
|
| 281 |
#undef TARGET_FRAME_POINTER_REQUIRED |
| 282 |
#define TARGET_FRAME_POINTER_REQUIRED cris_frame_pointer_required |
| 283 |
|
| 284 |
#undef TARGET_OPTION_OVERRIDE |
| 285 |
#define TARGET_OPTION_OVERRIDE cris_option_override |
| 286 |
#undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE |
| 287 |
#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE cris_option_override_after_change |
| 288 |
|
| 289 |
#undef TARGET_ASM_TRAMPOLINE_TEMPLATE |
| 290 |
#define TARGET_ASM_TRAMPOLINE_TEMPLATE cris_asm_trampoline_template |
| 291 |
#undef TARGET_TRAMPOLINE_INIT |
| 292 |
#define TARGET_TRAMPOLINE_INIT cris_trampoline_init |
| 293 |
|
| 294 |
#undef TARGET_FUNCTION_VALUE |
| 295 |
#define TARGET_FUNCTION_VALUE cris_function_value |
| 296 |
#undef TARGET_LIBCALL_VALUE |
| 297 |
#define TARGET_LIBCALL_VALUE cris_libcall_value |
| 298 |
#undef TARGET_FUNCTION_VALUE_REGNO_P |
| 299 |
#define TARGET_FUNCTION_VALUE_REGNO_P cris_function_value_regno_p |
| 300 |
|
| 301 |
#undef TARGET_HARD_REGNO_NREGS |
| 302 |
#define TARGET_HARD_REGNO_NREGS cris_hard_regno_nregs |
| 303 |
#undef TARGET_HARD_REGNO_MODE_OK |
| 304 |
#define TARGET_HARD_REGNO_MODE_OK cris_hard_regno_mode_ok |
| 305 |
|
| 306 |
#undef TARGET_STATIC_RTX_ALIGNMENT |
| 307 |
#define TARGET_STATIC_RTX_ALIGNMENT cris_static_rtx_alignment |
| 308 |
#undef TARGET_CONSTANT_ALIGNMENT |
| 309 |
#define TARGET_CONSTANT_ALIGNMENT cris_constant_alignment |
| 310 |
|
| 311 |
struct gcc_target targetm = TARGET_INITIALIZER; |
| 312 |
|
| 313 |
namespace { |
| 314 |
|
| 315 |
const pass_data pass_data_cris_postdbr_cmpelim = |
| 316 |
{ |
| 317 |
RTL_PASS, /* type */ |
| 318 |
"mach2", /* name */ |
| 319 |
OPTGROUP_NONE, /* optinfo_flags */ |
| 320 |
TV_MACH_DEP, /* tv_id */ |
| 321 |
0, /* properties_required */ |
| 322 |
0, /* properties_provided */ |
| 323 |
0, /* properties_destroyed */ |
| 324 |
0, /* todo_flags_start */ |
| 325 |
0, /* todo_flags_finish */ |
| 326 |
}; |
| 327 |
|
| 328 |
class pass_cris_postdbr_cmpelim : public rtl_opt_pass |
| 329 |
{ |
| 330 |
public: |
| 331 |
pass_cris_postdbr_cmpelim (gcc::context *ctxt) |
| 332 |
: rtl_opt_pass (pass_data_cris_postdbr_cmpelim, ctxt) |
| 333 |
{} |
| 334 |
|
| 335 |
/* opt_pass methods: */ |
| 336 |
virtual unsigned int execute (function *) |
| 337 |
{ |
| 338 |
return cris_postdbr_cmpelim (); |
| 339 |
} |
| 340 |
|
| 341 |
/* No use running this if reorg and cmpelim aren't both run. */ |
| 342 |
virtual bool gate (function *) |
| 343 |
{ |
| 344 |
return |
| 345 |
optimize > 0 |
| 346 |
&& flag_delayed_branch |
| 347 |
&& flag_compare_elim_after_reload; |
| 348 |
} |
| 349 |
}; |
| 350 |
|
| 351 |
} // anon namespace |
| 352 |
|
| 353 |
rtl_opt_pass * |
| 354 |
make_pass_cris_postdbr_cmpelim (gcc::context *ctxt) |
| 355 |
{ |
| 356 |
return new pass_cris_postdbr_cmpelim (ctxt); |
| 357 |
} |
| 358 |
|
| 359 |
/* "Cheap version" of cmpelim, making use of the opportunities opened up |
| 360 |
by reorg. |
| 361 |
|
| 362 |
Go through the insns of a function and look at each actual compare |
| 363 |
insn; considering only those that compare a register to 0. If the |
| 364 |
previous CC-affecting insn sets the compared register or if a move |
| 365 |
reads from it, try to change that into a CC-setting move and try to |
| 366 |
have it recognized. Bail at labels or non-matching insns that |
| 367 |
clobber the compared register. If successful, delete the compare. |
| 368 |
|
| 369 |
Also, reorg isn't up to date regarding data-flow handling, so we |
| 370 |
can't go beyond classic RTL scanning. */ |
| 371 |
|
| 372 |
static unsigned int |
| 373 |
cris_postdbr_cmpelim () |
| 374 |
{ |
| 375 |
rtx_insn *insn; |
| 376 |
rtx_insn *next; |
| 377 |
rtx_insn *prev_cc_setter = 0; |
| 378 |
rtx_insn *prev_cc_outer = 0; |
| 379 |
rtx dccr = gen_rtx_REG (CCmode, CRIS_CC0_REGNUM); |
| 380 |
|
| 381 |
/* Now look for compares in the insn stream. */ |
| 382 |
for (insn = get_insns (); insn; insn = next) |
| 383 |
{ |
| 384 |
rtx_insn *outer_insn = insn; |
| 385 |
|
| 386 |
next = NEXT_INSN (outer_insn); |
| 387 |
|
| 388 |
/* Forget previous state when we see a label; we can't track or |
| 389 |
merge its state. */ |
| 390 |
if (LABEL_P (insn)) |
| 391 |
{ |
| 392 |
prev_cc_setter = 0; |
| 393 |
continue; |
| 394 |
} |
| 395 |
|
| 396 |
if (!NONDEBUG_INSN_P (insn)) |
| 397 |
continue; |
| 398 |
rtx pat = PATTERN (insn); |
| 399 |
|
| 400 |
/* Consider filled delay slots; there might be a comparison there. |
| 401 |
It's only the second insn in a sequence that is interesting. */ |
| 402 |
if (GET_CODE (pat) == SEQUENCE) |
| 403 |
insn = as_a <rtx_insn *> (XVECEXP (pat, 0, 1)); |
| 404 |
/* The "else" eliminates temptations to consider an insn in a |
| 405 |
delay slot for elimination; it can only be a prev_cc_setter. */ |
| 406 |
else if (prev_cc_setter != 0 && GET_CODE (pat) == SET) |
| 407 |
{ |
| 408 |
rtx dest = SET_DEST (pat); |
| 409 |
rtx src = SET_SRC (pat); |
| 410 |
rtx prev_set; |
| 411 |
|
| 412 |
if (REG_P (dest) |
| 413 |
&& REGNO (dest) == CRIS_CC0_REGNUM |
| 414 |
&& GET_CODE (src) == COMPARE |
| 415 |
&& REG_P (XEXP (src, 0)) |
| 416 |
&& XEXP (src, 1) == const0_rtx |
| 417 |
&& (prev_set = single_set (prev_cc_setter)) != 0) |
| 418 |
{ |
| 419 |
/* We have a candidate, and a prev_cc_setter to inspect. */ |
| 420 |
rtx reg = XEXP (src, 0); |
| 421 |
rtx prev_dest = SET_DEST (prev_set); |
| 422 |
rtx prev_src = SET_SRC (prev_set); |
| 423 |
bool src_same = rtx_equal_p (prev_src, reg); |
| 424 |
|
| 425 |
/* If the prev_cc_setter isn't a simple SET, or if the |
| 426 |
compared register is modified in prev_cc_setter without |
| 427 |
being the destination, or if it's modified between |
| 428 |
prev_cc_setter (equal to or contained in prev_cc_outer) |
| 429 |
and this insn, then we can't use the flags result. And |
| 430 |
of course, the SET_DEST of prev_cc_setter (the main |
| 431 |
interest, not dccr) has to be the same register and |
| 432 |
mode we're interested in - or the SET_SRC. We've |
| 433 |
already checked that the compared register isn't |
| 434 |
changed in-between. */ |
| 435 |
if (REG_P (prev_dest) |
| 436 |
&& ! reg_set_p (reg, prev_src) |
| 437 |
&& ! reg_set_between_p (reg, prev_cc_outer, outer_insn) |
| 438 |
&& (src_same || rtx_equal_p (prev_dest, reg))) |
| 439 |
{ |
| 440 |
machine_mode ccmode = GET_MODE (src); |
| 441 |
rtx modeadjusted_dccr |
| 442 |
= (ccmode == CCmode ? dccr |
| 443 |
: gen_rtx_REG (ccmode, CRIS_CC0_REGNUM)); |
| 444 |
rtx compare |
| 445 |
/* We don't need to copy_rtx pat: we're going to |
| 446 |
delete that insn. */ |
| 447 |
= (src_same ? pat |
| 448 |
: gen_rtx_SET (modeadjusted_dccr, |
| 449 |
gen_rtx_COMPARE (ccmode, |
| 450 |
copy_rtx (prev_src), |
| 451 |
const0_rtx))); |
| 452 |
|
| 453 |
/* Replace tentatively, the prev_set combo that is |
| 454 |
((set d s) (clobber dccr)) with |
| 455 |
((cmp s 0) (set d s)) where (cmp s 0) is the |
| 456 |
compare we're looking at, and validate it or fail |
| 457 |
the whole thing. First replace the ((set d s) ...) |
| 458 |
with ((cmp s 0) ...)). */ |
| 459 |
validate_change (prev_cc_setter, |
| 460 |
&XVECEXP (PATTERN (prev_cc_setter), |
| 461 |
0, 0), compare, true); |
| 462 |
|
| 463 |
/* Then the clobber with the (set d s). */ |
| 464 |
validate_change (prev_cc_setter, |
| 465 |
&XVECEXP (PATTERN (prev_cc_setter), |
| 466 |
0, 1), prev_set, true); |
| 467 |
|
| 468 |
if (apply_change_group ()) |
| 469 |
{ |
| 470 |
delete_insn (insn); |
| 471 |
|
| 472 |
/* We eliminated the compare. Then we must go to |
| 473 |
the next insn: we can't consider the eliminated |
| 474 |
insn for the next prev_cc_setter. |
| 475 |
|
| 476 |
FIXME: if later insns still match, we could do |
| 477 |
the delete_insn part only, for them. But, it |
| 478 |
seems rare that reorg would manage to move a |
| 479 |
second CC-clobber to another delay-slot, |
| 480 |
leaving two identical compares (and presumably |
| 481 |
users). */ |
| 482 |
prev_cc_setter = 0; |
| 483 |
continue; |
| 484 |
} |
| 485 |
} |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
if (reg_set_p (dccr, insn)) |
| 490 |
{ |
| 491 |
rtx pat = PATTERN (insn); |
| 492 |
|
| 493 |
prev_cc_setter = 0; |
| 494 |
|
| 495 |
/* Make sure we can use it later on, otherwise forget it. |
| 496 |
Don't look too close, we're going to pass a lot of these. |
| 497 |
Just make sure the structure is that we can work with. */ |
| 498 |
if (GET_CODE (pat) == PARALLEL |
| 499 |
&& XVECLEN (pat, 0) == 2 |
| 500 |
&& GET_CODE (XVECEXP (pat, 0, 1)) == CLOBBER) |
| 501 |
{ |
| 502 |
prev_cc_setter = insn; |
| 503 |
prev_cc_outer = outer_insn; |
| 504 |
} |
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
return 0; |
| 509 |
} |
| 510 |
|
| 511 |
/* Helper for cris_load_multiple_op and cris_ret_movem_op. */ |
| 512 |
|
| 513 |
bool |
| 514 |
cris_movem_load_rest_p (rtx op) |
| 515 |
{ |
| 516 |
unsigned int reg_count = XVECLEN (op, 0); |
| 517 |
rtx src_addr; |
| 518 |
int i; |
| 519 |
rtx elt; |
| 520 |
int setno; |
| 521 |
int regno_dir = 1; |
| 522 |
unsigned int regno = 0; |
| 523 |
|
| 524 |
/* Perform a quick check so we don't blow up below. FIXME: Adjust for |
| 525 |
other than (MEM reg). */ |
| 526 |
if (reg_count <= 1 |
| 527 |
|| GET_CODE (XVECEXP (op, 0, 0)) != SET |
| 528 |
|| !REG_P (SET_DEST (XVECEXP (op, 0, 0))) |
| 529 |
|| !MEM_P (SET_SRC (XVECEXP (op, 0, 0)))) |
| 530 |
return false; |
| 531 |
|
| 532 |
/* Check a possible post-inc indicator. */ |
| 533 |
if (GET_CODE (XVECEXP (op, 0, 1)) == SET |
| 534 |
&& GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS) |
| 535 |
{ |
| 536 |
rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 0); |
| 537 |
rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1); |
| 538 |
|
| 539 |
reg_count--; |
| 540 |
|
| 541 |
if (reg_count == 1 |
| 542 |
|| !REG_P (reg) |
| 543 |
|| !REG_P (SET_DEST (XVECEXP (op, 0, 1))) |
| 544 |
|| REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, 1))) |
| 545 |
|| !CONST_INT_P (inc) |
| 546 |
|| INTVAL (inc) != (HOST_WIDE_INT) reg_count * 4) |
| 547 |
return false; |
| 548 |
i = 2; |
| 549 |
} |
| 550 |
else |
| 551 |
i = 1; |
| 552 |
|
| 553 |
regno_dir = -1; |
| 554 |
regno = reg_count - 1; |
| 555 |
|
| 556 |
elt = XVECEXP (op, 0, 0); |
| 557 |
src_addr = XEXP (SET_SRC (elt), 0); |
| 558 |
|
| 559 |
if (GET_CODE (elt) != SET |
| 560 |
|| !REG_P (SET_DEST (elt)) |
| 561 |
|| GET_MODE (SET_DEST (elt)) != SImode |
| 562 |
|| REGNO (SET_DEST (elt)) != regno |
| 563 |
|| !MEM_P (SET_SRC (elt)) |
| 564 |
|| GET_MODE (SET_SRC (elt)) != SImode |
| 565 |
|| !memory_address_p (SImode, src_addr)) |
| 566 |
return false; |
| 567 |
|
| 568 |
for (setno = 1; i < XVECLEN (op, 0); setno++, i++) |
| 569 |
{ |
| 570 |
rtx elt = XVECEXP (op, 0, i); |
| 571 |
regno += regno_dir; |
| 572 |
|
| 573 |
if (GET_CODE (elt) != SET |
| 574 |
|| !REG_P (SET_DEST (elt)) |
| 575 |
|| GET_MODE (SET_DEST (elt)) != SImode |
| 576 |
|| REGNO (SET_DEST (elt)) != regno |
| 577 |
|| !MEM_P (SET_SRC (elt)) |
| 578 |
|| GET_MODE (SET_SRC (elt)) != SImode |
| 579 |
|| GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS |
| 580 |
|| ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) |
| 581 |
|| !CONST_INT_P (XEXP (XEXP (SET_SRC (elt), 0), 1)) |
| 582 |
|| INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != setno * 4) |
| 583 |
return false; |
| 584 |
} |
| 585 |
|
| 586 |
return true; |
| 587 |
} |
| 588 |
|
| 589 |
/* Worker function for predicate for the parallel contents in a movem |
| 590 |
to-memory. */ |
| 591 |
|
| 592 |
bool |
| 593 |
cris_store_multiple_op_p (rtx op) |
| 594 |
{ |
| 595 |
int reg_count = XVECLEN (op, 0); |
| 596 |
rtx dest; |
| 597 |
rtx dest_addr; |
| 598 |
rtx dest_base; |
| 599 |
int i; |
| 600 |
rtx elt; |
| 601 |
int setno; |
| 602 |
int regno_dir = 1; |
| 603 |
int regno = 0; |
| 604 |
int offset = 0; |
| 605 |
|
| 606 |
/* Perform a quick check so we don't blow up below. FIXME: Adjust for |
| 607 |
other than (MEM reg) and (MEM (PLUS reg const)). */ |
| 608 |
if (reg_count <= 1) |
| 609 |
return false; |
| 610 |
|
| 611 |
elt = XVECEXP (op, 0, 0); |
| 612 |
|
| 613 |
if (GET_CODE (elt) != SET) |
| 614 |
return false; |
| 615 |
|
| 616 |
dest = SET_DEST (elt); |
| 617 |
|
| 618 |
if (!REG_P (SET_SRC (elt)) || !MEM_P (dest)) |
| 619 |
return false; |
| 620 |
|
| 621 |
dest_addr = XEXP (dest, 0); |
| 622 |
|
| 623 |
/* Check a possible post-inc indicator. */ |
| 624 |
if (GET_CODE (XVECEXP (op, 0, 1)) == SET |
| 625 |
&& GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS) |
| 626 |
{ |
| 627 |
rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 0); |
| 628 |
rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1); |
| 629 |
|
| 630 |
reg_count--; |
| 631 |
|
| 632 |
if (!REG_P (reg) |
| 633 |
|| !REG_P (SET_DEST (XVECEXP (op, 0, 1))) |
| 634 |
|| REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, 1))) |
| 635 |
|| !CONST_INT_P (inc) |
| 636 |
/* Support increment by number of registers, and by the offset |
| 637 |
of the destination, if it has the form (MEM (PLUS reg |
| 638 |
offset)). */ |
| 639 |
|| !((REG_P (dest_addr) |
| 640 |
&& REGNO (dest_addr) == REGNO (reg) |
| 641 |
&& INTVAL (inc) == (HOST_WIDE_INT) reg_count * 4) |
| 642 |
|| (GET_CODE (dest_addr) == PLUS |
| 643 |
&& REG_P (XEXP (dest_addr, 0)) |
| 644 |
&& REGNO (XEXP (dest_addr, 0)) == REGNO (reg) |
| 645 |
&& CONST_INT_P (XEXP (dest_addr, 1)) |
| 646 |
&& INTVAL (XEXP (dest_addr, 1)) == INTVAL (inc)))) |
| 647 |
return false; |
| 648 |
|
| 649 |
i = 2; |
| 650 |
} |
| 651 |
else |
| 652 |
i = 1; |
| 653 |
|
| 654 |
regno_dir = -1; |
| 655 |
regno = reg_count - 1; |
| 656 |
|
| 657 |
if (GET_CODE (elt) != SET |
| 658 |
|| !REG_P (SET_SRC (elt)) |
| 659 |
|| GET_MODE (SET_SRC (elt)) != SImode |
| 660 |
|| REGNO (SET_SRC (elt)) != (unsigned int) regno |
| 661 |
|| !MEM_P (SET_DEST (elt)) |
| 662 |
|| GET_MODE (SET_DEST (elt)) != SImode) |
| 663 |
return false; |
| 664 |
|
| 665 |
if (REG_P (dest_addr)) |
| 666 |
{ |
| 667 |
dest_base = dest_addr; |
| 668 |
offset = 0; |
| 669 |
} |
| 670 |
else if (GET_CODE (dest_addr) == PLUS |
| 671 |
&& REG_P (XEXP (dest_addr, 0)) |
| 672 |
&& CONST_INT_P (XEXP (dest_addr, 1))) |
| 673 |
{ |
| 674 |
dest_base = XEXP (dest_addr, 0); |
| 675 |
offset = INTVAL (XEXP (dest_addr, 1)); |
| 676 |
} |
| 677 |
else |
| 678 |
return false; |
| 679 |
|
| 680 |
for (setno = 1; i < XVECLEN (op, 0); setno++, i++) |
| 681 |
{ |
| 682 |
rtx elt = XVECEXP (op, 0, i); |
| 683 |
regno += regno_dir; |
| 684 |
|
| 685 |
if (GET_CODE (elt) != SET |
| 686 |
|| !REG_P (SET_SRC (elt)) |
| 687 |
|| GET_MODE (SET_SRC (elt)) != SImode |
| 688 |
|| REGNO (SET_SRC (elt)) != (unsigned int) regno |
| 689 |
|| !MEM_P (SET_DEST (elt)) |
| 690 |
|| GET_MODE (SET_DEST (elt)) != SImode |
| 691 |
|| GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS |
| 692 |
|| ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_base) |
| 693 |
|| !CONST_INT_P (XEXP (XEXP (SET_DEST (elt), 0), 1)) |
| 694 |
|| INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != setno * 4 + offset) |
| 695 |
return false; |
| 696 |
} |
| 697 |
|
| 698 |
return true; |
| 699 |
} |
| 700 |
|
| 701 |
/* The TARGET_CONDITIONAL_REGISTER_USAGE worker. */ |
| 702 |
|
| 703 |
static void |
| 704 |
cris_conditional_register_usage (void) |
| 705 |
{ |
| 706 |
if (TARGET_HAS_MUL_INSNS) |
| 707 |
fixed_regs[CRIS_MOF_REGNUM] = 0; |
| 708 |
|
| 709 |
/* On early versions, we must use the 16-bit condition-code register, |
| 710 |
which has another name. */ |
| 711 |
if (cris_cpu_version < 8) |
| 712 |
reg_names[CRIS_CC0_REGNUM] = "ccr"; |
| 713 |
} |
| 714 |
|
| 715 |
/* Given an rtx, return the text string corresponding to the CODE of X. |
| 716 |
Intended for use in the assembly language output section of a |
| 717 |
define_insn. */ |
| 718 |
|
| 719 |
const char * |
| 720 |
cris_op_str (rtx x) |
| 721 |
{ |
| 722 |
cris_output_insn_is_bound = 0; |
| 723 |
switch (GET_CODE (x)) |
| 724 |
{ |
| 725 |
case PLUS: |
| 726 |
return "add"; |
| 727 |
|
| 728 |
case MINUS: |
| 729 |
return "sub"; |
| 730 |
|
| 731 |
case MULT: |
| 732 |
/* This function is for retrieving a part of an instruction name for |
| 733 |
an operator, for immediate output. If that ever happens for |
| 734 |
MULT, we need to apply TARGET_MUL_BUG in the caller. Make sure |
| 735 |
we notice. */ |
| 736 |
internal_error ("MULT case in %<cris_op_str%>"); |
| 737 |
break; |
| 738 |
|
| 739 |
case DIV: |
| 740 |
return "div"; |
| 741 |
|
| 742 |
case AND: |
| 743 |
return "and"; |
| 744 |
|
| 745 |
case IOR: |
| 746 |
return "or"; |
| 747 |
|
| 748 |
case XOR: |
| 749 |
return "xor"; |
| 750 |
|
| 751 |
case NOT: |
| 752 |
return "not"; |
| 753 |
|
| 754 |
case ASHIFT: |
| 755 |
return "lsl"; |
| 756 |
|
| 757 |
case LSHIFTRT: |
| 758 |
return "lsr"; |
| 759 |
|
| 760 |
case ASHIFTRT: |
| 761 |
return "asr"; |
| 762 |
|
| 763 |
case UMIN: |
| 764 |
/* Used to control the sign/zero-extend character for the 'E' modifier. |
| 765 |
BOUND has none. */ |
| 766 |
cris_output_insn_is_bound = 1; |
| 767 |
return "bound"; |
| 768 |
|
| 769 |
default: |
| 770 |
return "Unknown operator"; |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
/* Emit an error message when we're in an asm, and a fatal error for |
| 775 |
"normal" insns. Formatted output isn't easily implemented, since we |
| 776 |
use output_operand_lossage to output the actual message and handle the |
| 777 |
categorization of the error. */ |
| 778 |
|
| 779 |
static void |
| 780 |
cris_operand_lossage (const char *msgid, rtx op) |
| 781 |
{ |
| 782 |
debug_rtx (op); |
| 783 |
output_operand_lossage ("%s", msgid); |
| 784 |
} |
| 785 |
|
| 786 |
/* Print an index part of an address to file. */ |
| 787 |
|
| 788 |
static void |
| 789 |
cris_print_index (rtx index, FILE *file) |
| 790 |
{ |
| 791 |
/* Make the index "additive" unless we'll output a negative number, in |
| 792 |
which case the sign character is free (as in free beer). */ |
| 793 |
if (!CONST_INT_P (index) || INTVAL (index) >= 0) |
| 794 |
putc ('+', file); |
| 795 |
|
| 796 |
if (REG_P (index)) |
| 797 |
fprintf (file, "$%s.b", reg_names[REGNO (index)]); |
| 798 |
else if (CONSTANT_P (index)) |
| 799 |
cris_output_addr_const (file, index); |
| 800 |
else if (GET_CODE (index) == MULT) |
| 801 |
{ |
| 802 |
fprintf (file, "$%s.", |
| 803 |
reg_names[REGNO (XEXP (index, 0))]); |
| 804 |
|
| 805 |
putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file); |
| 806 |
} |
| 807 |
else if (GET_CODE (index) == SIGN_EXTEND && MEM_P (XEXP (index, 0))) |
| 808 |
{ |
| 809 |
rtx inner = XEXP (index, 0); |
| 810 |
rtx inner_inner = XEXP (inner, 0); |
| 811 |
|
| 812 |
if (GET_CODE (inner_inner) == POST_INC) |
| 813 |
{ |
| 814 |
fprintf (file, "[$%s+].", |
| 815 |
reg_names[REGNO (XEXP (inner_inner, 0))]); |
| 816 |
putc (GET_MODE (inner) == HImode ? 'w' : 'b', file); |
| 817 |
} |
| 818 |
else |
| 819 |
{ |
| 820 |
fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]); |
| 821 |
|
| 822 |
putc (GET_MODE (inner) == HImode ? 'w' : 'b', file); |
| 823 |
} |
| 824 |
} |
| 825 |
else if (MEM_P (index)) |
| 826 |
{ |
| 827 |
rtx inner = XEXP (index, 0); |
| 828 |
if (GET_CODE (inner) == POST_INC) |
| 829 |
fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]); |
| 830 |
else |
| 831 |
fprintf (file, "[$%s].d", reg_names[REGNO (inner)]); |
| 832 |
} |
| 833 |
else |
| 834 |
cris_operand_lossage ("unexpected index-type in cris_print_index", |
| 835 |
index); |
| 836 |
} |
| 837 |
|
| 838 |
/* Print a base rtx of an address to file. */ |
| 839 |
|
| 840 |
static void |
| 841 |
cris_print_base (rtx base, FILE *file) |
| 842 |
{ |
| 843 |
if (REG_P (base)) |
| 844 |
fprintf (file, "$%s", reg_names[REGNO (base)]); |
| 845 |
else if (GET_CODE (base) == POST_INC) |
| 846 |
fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]); |
| 847 |
else |
| 848 |
cris_operand_lossage ("unexpected base-type in cris_print_base", |
| 849 |
base); |
| 850 |
} |
| 851 |
|
| 852 |
/* Usable as a guard in expressions. */ |
| 853 |
|
| 854 |
int |
| 855 |
cris_fatal (char *arg) |
| 856 |
{ |
| 857 |
internal_error (arg); |
| 858 |
|
| 859 |
/* We'll never get here; this is just to appease compilers. */ |
| 860 |
return 0; |
| 861 |
} |
| 862 |
|
| 863 |
/* Return nonzero if REGNO is an ordinary register that *needs* to be |
| 864 |
saved together with other registers, possibly by a MOVEM instruction, |
| 865 |
or is saved for target-independent reasons. There may be |
| 866 |
target-dependent reasons to save the register anyway; this is just a |
| 867 |
wrapper for a complicated conditional. */ |
| 868 |
|
| 869 |
static int |
| 870 |
cris_reg_saved_in_regsave_area (unsigned int regno) |
| 871 |
{ |
| 872 |
return |
| 873 |
(((df_regs_ever_live_p (regno) |
| 874 |
&& !call_used_or_fixed_reg_p (regno))) |
| 875 |
&& (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed) |
| 876 |
&& regno != CRIS_SRP_REGNUM) |
| 877 |
|| (crtl->calls_eh_return |
| 878 |
&& (regno == EH_RETURN_DATA_REGNO (0) |
| 879 |
|| regno == EH_RETURN_DATA_REGNO (1) |
| 880 |
|| regno == EH_RETURN_DATA_REGNO (2) |
| 881 |
|| regno == EH_RETURN_DATA_REGNO (3))); |
| 882 |
} |
| 883 |
|
| 884 |
/* The PRINT_OPERAND worker. */ |
| 885 |
|
| 886 |
static void |
| 887 |
cris_print_operand (FILE *file, rtx x, int code) |
| 888 |
{ |
| 889 |
rtx operand = x; |
| 890 |
|
| 891 |
/* New code entries should just be added to the switch below. If |
| 892 |
handling is finished, just return. If handling was just a |
| 893 |
modification of the operand, the modified operand should be put in |
| 894 |
"operand", and then do a break to let default handling |
| 895 |
(zero-modifier) output the operand. */ |
| 896 |
|
| 897 |
switch (code) |
| 898 |
{ |
| 899 |
case 'b': |
| 900 |
/* Print the unsigned supplied integer as if it were signed |
| 901 |
and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc. */ |
| 902 |
if (!satisfies_constraint_O (x)) |
| 903 |
LOSE_AND_RETURN ("invalid operand for 'b' modifier", x); |
| 904 |
fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
| 905 |
INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535)); |
| 906 |
return; |
| 907 |
|
| 908 |
case 'x': |
| 909 |
/* Print assembler code for operator. */ |
| 910 |
fprintf (file, "%s", cris_op_str (operand)); |
| 911 |
return; |
| 912 |
|
| 913 |
case 'o': |
| 914 |
{ |
| 915 |
/* A movem modifier working on a parallel; output the register |
| 916 |
name. */ |
| 917 |
int regno; |
| 918 |
|
| 919 |
if (GET_CODE (x) != PARALLEL) |
| 920 |
LOSE_AND_RETURN ("invalid operand for 'o' modifier", x); |
| 921 |
|
| 922 |
/* The second item can be (set reg (plus reg const)) to denote a |
| 923 |
postincrement. */ |
| 924 |
regno |
| 925 |
= (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS |
| 926 |
? XVECLEN (x, 0) - 2 |
| 927 |
: XVECLEN (x, 0) - 1); |
| 928 |
|
| 929 |
fprintf (file, "$%s", reg_names [regno]); |
| 930 |
} |
| 931 |
return; |
| 932 |
|
| 933 |
case 'O': |
| 934 |
{ |
| 935 |
/* A similar movem modifier; output the memory operand. */ |
| 936 |
rtx addr; |
| 937 |
|
| 938 |
if (GET_CODE (x) != PARALLEL) |
| 939 |
LOSE_AND_RETURN ("invalid operand for 'O' modifier", x); |
| 940 |
|
| 941 |
/* The lowest mem operand is in the first item, but perhaps it |
| 942 |
needs to be output as postincremented. */ |
| 943 |
addr = MEM_P (SET_SRC (XVECEXP (x, 0, 0))) |
| 944 |
? XEXP (SET_SRC (XVECEXP (x, 0, 0)), 0) |
| 945 |
: XEXP (SET_DEST (XVECEXP (x, 0, 0)), 0); |
| 946 |
|
| 947 |
/* The second item can be a (set reg (plus reg const)) to denote |
| 948 |
a modification. */ |
| 949 |
if (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS) |
| 950 |
{ |
| 951 |
/* It's a post-increment, if the address is a naked (reg). */ |
| 952 |
if (REG_P (addr)) |
| 953 |
addr = gen_rtx_POST_INC (SImode, addr); |
| 954 |
else |
| 955 |
{ |
| 956 |
/* Otherwise, it's a side-effect; RN=RN+M. */ |
| 957 |
fprintf (file, "[$%s=$%s%s%d]", |
| 958 |
reg_names [REGNO (SET_DEST (XVECEXP (x, 0, 1)))], |
| 959 |
reg_names [REGNO (XEXP (addr, 0))], |
| 960 |
INTVAL (XEXP (addr, 1)) < 0 ? "" : "+", |
| 961 |
(int) INTVAL (XEXP (addr, 1))); |
| 962 |
return; |
| 963 |
} |
| 964 |
} |
| 965 |
output_address (VOIDmode, addr); |
| 966 |
} |
| 967 |
return; |
| 968 |
|
| 969 |
case 'p': |
| 970 |
/* Adjust a power of two to its log2. */ |
| 971 |
if (!CONST_INT_P (x) || exact_log2 (INTVAL (x)) < 0 ) |
| 972 |
LOSE_AND_RETURN ("invalid operand for 'p' modifier", x); |
| 973 |
fprintf (file, "%d", exact_log2 (INTVAL (x))); |
| 974 |
return; |
| 975 |
|
| 976 |
case 's': |
| 977 |
/* For an integer, print 'b' or 'w' if <= 255 or <= 65535 |
| 978 |
respectively. This modifier also terminates the inhibiting |
| 979 |
effects of the 'x' modifier. */ |
| 980 |
cris_output_insn_is_bound = 0; |
| 981 |
if (GET_MODE (x) == VOIDmode && CONST_INT_P (x)) |
| 982 |
{ |
| 983 |
if (INTVAL (x) >= 0) |
| 984 |
{ |
| 985 |
if (INTVAL (x) <= 255) |
| 986 |
putc ('b', file); |
| 987 |
else if (INTVAL (x) <= 65535) |
| 988 |
putc ('w', file); |
| 989 |
else |
| 990 |
putc ('d', file); |
| 991 |
} |
| 992 |
else |
| 993 |
putc ('d', file); |
| 994 |
return; |
| 995 |
} |
| 996 |
|
| 997 |
/* For a non-integer, print the size of the operand. */ |
| 998 |
putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode) |
| 999 |
? 'd' : GET_MODE (x) == HImode ? 'w' |
| 1000 |
: GET_MODE (x) == QImode ? 'b' |
| 1001 |
/* If none of the above, emit an erroneous size letter. */ |
| 1002 |
: 'X', |
| 1003 |
file); |
| 1004 |
return; |
| 1005 |
|
| 1006 |
case 'z': |
| 1007 |
/* Const_int: print b for -127 <= x <= 255, |
| 1008 |
w for -32768 <= x <= 65535, else die. */ |
| 1009 |
if (!CONST_INT_P (x) |
| 1010 |
|| INTVAL (x) < -32768 || INTVAL (x) > 65535) |
| 1011 |
LOSE_AND_RETURN ("invalid operand for 'z' modifier", x); |
| 1012 |
putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file); |
| 1013 |
return; |
| 1014 |
|
| 1015 |
case '#': |
| 1016 |
/* Output a 'nop' if there's nothing for the delay slot. |
| 1017 |
This method stolen from the sparc files. */ |
| 1018 |
if (dbr_sequence_length () == 0) |
| 1019 |
fputs ("\n\tnop", file); |
| 1020 |
return; |
| 1021 |
|
| 1022 |
case '!': |
| 1023 |
/* Output directive for alignment padded with "nop" insns. |
| 1024 |
Optimizing for size, it's plain 4-byte alignment, otherwise we |
| 1025 |
align the section to a cache-line (32 bytes) and skip at max 2 |
| 1026 |
bytes, i.e. we skip if it's the last insn on a cache-line. The |
| 1027 |
latter is faster by a small amount (for two test-programs 99.6% |
| 1028 |
and 99.9%) and larger by a small amount (ditto 100.1% and |
| 1029 |
100.2%). This is supposed to be the simplest yet performance- |
| 1030 |
wise least intrusive way to make sure the immediately following |
| 1031 |
(supposed) muls/mulu insn isn't located at the end of a |
| 1032 |
cache-line. */ |
| 1033 |
if (TARGET_MUL_BUG) |
| 1034 |
fputs (optimize_size |
| 1035 |
? ".p2alignw 2,0x050f\n\t" |
| 1036 |
: ".p2alignw 5,0x050f,2\n\t", file); |
| 1037 |
return; |
| 1038 |
|
| 1039 |
case 'H': |
| 1040 |
/* Print high (most significant) part of something. */ |
| 1041 |
switch (GET_CODE (operand)) |
| 1042 |
{ |
| 1043 |
case CONST_INT: |
| 1044 |
/* If we're having 64-bit HOST_WIDE_INTs, the whole (DImode) |
| 1045 |
value is kept here, and so may be other than 0 or -1. */ |
| 1046 |
fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
| 1047 |
INTVAL (operand_subword (operand, 1, 0, DImode))); |
| 1048 |
return; |
| 1049 |
|
| 1050 |
case CONST_DOUBLE: |
| 1051 |
/* High part of a long long constant. */ |
| 1052 |
if (GET_MODE (operand) == VOIDmode) |
| 1053 |
{ |
| 1054 |
fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_HIGH (x)); |
| 1055 |
return; |
| 1056 |
} |
| 1057 |
else |
| 1058 |
LOSE_AND_RETURN ("invalid operand for 'H' modifier", x); |
| 1059 |
|
| 1060 |
case REG: |
| 1061 |
/* Print reg + 1. Check that there's not an attempt to print |
| 1062 |
high-parts of registers like stack-pointer or higher, except |
| 1063 |
for SRP (where the "high part" is MOF). */ |
| 1064 |
if (REGNO (operand) > STACK_POINTER_REGNUM - 2 |
| 1065 |
&& (REGNO (operand) != CRIS_SRP_REGNUM |
| 1066 |
|| CRIS_SRP_REGNUM + 1 != CRIS_MOF_REGNUM |
| 1067 |
|| fixed_regs[CRIS_MOF_REGNUM] != 0)) |
| 1068 |
LOSE_AND_RETURN ("bad register", operand); |
| 1069 |
fprintf (file, "$%s", reg_names[REGNO (operand) + 1]); |
| 1070 |
return; |
| 1071 |
|
| 1072 |
case MEM: |
| 1073 |
/* Adjust memory address to high part. */ |
| 1074 |
{ |
| 1075 |
rtx adj_mem = operand; |
| 1076 |
int size |
| 1077 |
= GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT; |
| 1078 |
|
| 1079 |
/* Adjust so we can use two SImode in DImode. |
| 1080 |
Calling adj_offsettable_operand will make sure it is an |
| 1081 |
offsettable address. Don't do this for a postincrement |
| 1082 |
though; it should remain as it was. */ |
| 1083 |
if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC) |
| 1084 |
adj_mem |
| 1085 |
= adjust_address (adj_mem, GET_MODE (adj_mem), size / 2); |
| 1086 |
|
| 1087 |
output_address (VOIDmode, XEXP (adj_mem, 0)); |
| 1088 |
return; |
| 1089 |
} |
| 1090 |
|
| 1091 |
default: |
| 1092 |
LOSE_AND_RETURN ("invalid operand for 'H' modifier", x); |
| 1093 |
} |
| 1094 |
|
| 1095 |
case 'L': |
| 1096 |
/* Strip the MEM expression. */ |
| 1097 |
operand = XEXP (operand, 0); |
| 1098 |
break; |
| 1099 |
|
| 1100 |
case 'e': |
| 1101 |
/* Like 'E', but ignore state set by 'x'. FIXME: Use code |
| 1102 |
iterators and attributes in cris.md to avoid the need for %x |
| 1103 |
and %E (and %e) and state passed between those modifiers. */ |
| 1104 |
cris_output_insn_is_bound = 0; |
| 1105 |
/* FALL THROUGH. */ |
| 1106 |
case 'E': |
| 1107 |
/* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless |
| 1108 |
cris_output_insn_is_bound is nonzero. */ |
| 1109 |
if (GET_CODE (operand) != SIGN_EXTEND |
| 1110 |
&& GET_CODE (operand) != ZERO_EXTEND |
| 1111 |
&& !CONST_INT_P (operand)) |
| 1112 |
LOSE_AND_RETURN ("invalid operand for 'e' modifier", x); |
| 1113 |
|
| 1114 |
if (cris_output_insn_is_bound) |
| 1115 |
{ |
| 1116 |
cris_output_insn_is_bound = 0; |
| 1117 |
return; |
| 1118 |
} |
| 1119 |
|
| 1120 |
putc (GET_CODE (operand) == SIGN_EXTEND |
| 1121 |
|| (CONST_INT_P (operand) && INTVAL (operand) < 0) |
| 1122 |
? 's' : 'u', file); |
| 1123 |
return; |
| 1124 |
|
| 1125 |
case 'm': |
| 1126 |
/* Print the size letter of the inner element. We can do it by |
| 1127 |
calling ourselves with the 's' modifier. */ |
| 1128 |
if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND) |
| 1129 |
LOSE_AND_RETURN ("invalid operand for 'm' modifier", x); |
| 1130 |
cris_print_operand (file, XEXP (operand, 0), 's'); |
| 1131 |
return; |
| 1132 |
|
| 1133 |
case 'M': |
| 1134 |
/* Print the least significant part of operand. */ |
| 1135 |
if (GET_CODE (operand) == CONST_DOUBLE) |
| 1136 |
{ |
| 1137 |
fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x)); |
| 1138 |
return; |
| 1139 |
} |
| 1140 |
else if (HOST_BITS_PER_WIDE_INT > 32 && CONST_INT_P (operand)) |
| 1141 |
{ |
| 1142 |
fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
| 1143 |
INTVAL (x) & ((unsigned int) 0x7fffffff * 2 + 1)); |
| 1144 |
return; |
| 1145 |
} |
| 1146 |
/* Otherwise the least significant part equals the normal part, |
| 1147 |
so handle it normally. */ |
| 1148 |
break; |
| 1149 |
|
| 1150 |
case 'A': |
| 1151 |
/* When emitting an add for the high part of a DImode constant, we |
| 1152 |
want to use addq for 0 and adds.w for -1. */ |
| 1153 |
if (!CONST_INT_P (operand)) |
| 1154 |
LOSE_AND_RETURN ("invalid operand for 'A' modifier", x); |
| 1155 |
fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq"); |
| 1156 |
return; |
| 1157 |
|
| 1158 |
case 'P': |
| 1159 |
/* For const_int operands, print the additive mnemonic and the |
| 1160 |
modified operand (byte-sized operands don't save anything): |
| 1161 |
N=MIN_INT..-65536: add.d N |
| 1162 |
-65535..-64: subu.w -N |
| 1163 |
-63..-1: subq -N |
| 1164 |
0..63: addq N |
| 1165 |
64..65535: addu.w N |
| 1166 |
65536..MAX_INT: add.d N. |
| 1167 |
(Emitted mnemonics are capitalized to simplify testing.) |
| 1168 |
For anything else (N.B: only register is valid), print "add.d". */ |
| 1169 |
if (REG_P (operand)) |
| 1170 |
{ |
| 1171 |
fprintf (file, "Add.d "); |
| 1172 |
|
| 1173 |
/* Deal with printing the operand by dropping through to the |
| 1174 |
normal path. */ |
| 1175 |
break; |
| 1176 |
} |
| 1177 |
else |
| 1178 |
{ |
| 1179 |
int val; |
| 1180 |
gcc_assert (CONST_INT_P (operand)); |
| 1181 |
|
| 1182 |
val = INTVAL (operand); |
| 1183 |
if (!IN_RANGE (val, -65535, 65535)) |
| 1184 |
fprintf (file, "Add.d %d", val); |
| 1185 |
else if (val <= -64) |
| 1186 |
fprintf (file, "Subu.w %d", -val); |
| 1187 |
else if (val <= -1) |
| 1188 |
fprintf (file, "Subq %d", -val); |
| 1189 |
else if (val <= 63) |
| 1190 |
fprintf (file, "Addq %d", val); |
| 1191 |
else if (val <= 65535) |
| 1192 |
fprintf (file, "Addu.w %d", val); |
| 1193 |
return; |
| 1194 |
} |
| 1195 |
break; |
| 1196 |
|
| 1197 |
case 'q': |
| 1198 |
/* If the operand is an integer -31..31, print "q" else ".d". */ |
| 1199 |
if (CONST_INT_P (operand) && IN_RANGE (INTVAL (operand), -31, 31)) |
| 1200 |
fprintf (file, "q"); |
| 1201 |
else |
| 1202 |
fprintf (file, ".d"); |
| 1203 |
return; |
| 1204 |
|
| 1205 |
case 'D': |
| 1206 |
/* When emitting an sub for the high part of a DImode constant, we |
| 1207 |
want to use subq for 0 and subs.w for -1. */ |
| 1208 |
if (!CONST_INT_P (operand)) |
| 1209 |
LOSE_AND_RETURN ("invalid operand for 'D' modifier", x); |
| 1210 |
fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq"); |
| 1211 |
return; |
| 1212 |
|
| 1213 |
case 'S': |
| 1214 |
/* Print the operand as the index-part of an address. |
| 1215 |
Easiest way out is to use cris_print_index. */ |
| 1216 |
cris_print_index (operand, file); |
| 1217 |
return; |
| 1218 |
|
| 1219 |
case 'T': |
| 1220 |
{ |
| 1221 |
/* Print the size letter for an operand to a ASHIFT, which must be a |
| 1222 |
const_int with a suitable value. */ |
| 1223 |
int shiftval; |
| 1224 |
|
| 1225 |
if (!CONST_INT_P (operand)) |
| 1226 |
LOSE_AND_RETURN ("invalid operand for 'T' modifier", x); |
| 1227 |
|
| 1228 |
shiftval = INTVAL (operand); |
| 1229 |
|
| 1230 |
if (!(shiftval == 1 || shiftval == 2)) |
| 1231 |
LOSE_AND_RETURN ("invalid operand for 'T' modifier", x); |
| 1232 |
|
| 1233 |
fprintf (file, "%s", shiftval == 1 ? ".w" : ".d"); |
| 1234 |
} |
| 1235 |
return; |
| 1236 |
|
| 1237 |
case 0: |
| 1238 |
/* No code, print as usual. */ |
| 1239 |
break; |
| 1240 |
|
| 1241 |
default: |
| 1242 |
LOSE_AND_RETURN ("invalid operand modifier letter", x); |
| 1243 |
} |
| 1244 |
|
| 1245 |
/* Print an operand as without a modifier letter. */ |
| 1246 |
switch (GET_CODE (operand)) |
| 1247 |
{ |
| 1248 |
case REG: |
| 1249 |
if (REGNO (operand) > 15 |
| 1250 |
&& REGNO (operand) != CRIS_MOF_REGNUM |
| 1251 |
&& REGNO (operand) != CRIS_SRP_REGNUM |
| 1252 |
&& REGNO (operand) != CRIS_CC0_REGNUM) |
| 1253 |
internal_error ("internal error: bad register: %d", REGNO (operand)); |
| 1254 |
fprintf (file, "$%s", reg_names[REGNO (operand)]); |
| 1255 |
return; |
| 1256 |
|
| 1257 |
case MEM: |
| 1258 |
output_address (GET_MODE (operand), XEXP (operand, 0)); |
| 1259 |
return; |
| 1260 |
|
| 1261 |
case CONST_DOUBLE: |
| 1262 |
if (GET_MODE (operand) == VOIDmode) |
| 1263 |
/* A long long constant. */ |
| 1264 |
output_addr_const (file, operand); |
| 1265 |
else |
| 1266 |
{ |
| 1267 |
/* Only single precision is allowed as plain operands the |
| 1268 |
moment. */ |
| 1269 |
long l; |
| 1270 |
|
| 1271 |
/* FIXME: Perhaps check overflow of the "single". */ |
| 1272 |
REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (operand), l); |
| 1273 |
|
| 1274 |
fprintf (file, "0x%lx", l); |
| 1275 |
} |
| 1276 |
return; |
| 1277 |
|
| 1278 |
case CONST: |
| 1279 |
cris_output_addr_const (file, operand); |
| 1280 |
return; |
| 1281 |
|
| 1282 |
case MULT: |
| 1283 |
case ASHIFT: |
| 1284 |
{ |
| 1285 |
/* For a (MULT (reg X) const_int) we output "rX.S". */ |
| 1286 |
int i = CONST_INT_P (XEXP (operand, 1)) |
| 1287 |
? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0)); |
| 1288 |
rtx reg = CONST_INT_P (XEXP (operand, 1)) |
| 1289 |
? XEXP (operand, 0) : XEXP (operand, 1); |
| 1290 |
|
| 1291 |
if (!REG_P (reg) |
| 1292 |
|| (!CONST_INT_P (XEXP (operand, 0)) |
| 1293 |
&& !CONST_INT_P (XEXP (operand, 1)))) |
| 1294 |
LOSE_AND_RETURN ("unexpected multiplicative operand", x); |
| 1295 |
|
| 1296 |
cris_print_base (reg, file); |
| 1297 |
fprintf (file, ".%c", |
| 1298 |
i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b' |
| 1299 |
: i == 4 ? 'd' |
| 1300 |
: (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w' |
| 1301 |
: 'd'); |
| 1302 |
return; |
| 1303 |
} |
| 1304 |
|
| 1305 |
default: |
| 1306 |
/* No need to handle all strange variants, let output_addr_const |
| 1307 |
do it for us. */ |
| 1308 |
if (CONSTANT_P (operand)) |
| 1309 |
{ |
| 1310 |
cris_output_addr_const (file, operand); |
| 1311 |
return; |
| 1312 |
} |
| 1313 |
|
| 1314 |
LOSE_AND_RETURN ("unexpected operand", x); |
| 1315 |
} |
| 1316 |
} |
| 1317 |
|
| 1318 |
static bool |
| 1319 |
cris_print_operand_punct_valid_p (unsigned char code) |
| 1320 |
{ |
| 1321 |
return (code == '#' || code == '!'); |
| 1322 |
} |
| 1323 |
|
| 1324 |
/* The PRINT_OPERAND_ADDRESS worker. */ |
| 1325 |
|
| 1326 |
static void |
| 1327 |
cris_print_operand_address (FILE *file, machine_mode /*mode*/, rtx x) |
| 1328 |
{ |
| 1329 |
/* All these were inside MEM:s so output indirection characters. */ |
| 1330 |
putc ('[', file); |
| 1331 |
|
| 1332 |
if (CONSTANT_ADDRESS_P (x)) |
| 1333 |
cris_output_addr_const (file, x); |
| 1334 |
else if (cris_base_or_autoincr_p (x, true)) |
| 1335 |
cris_print_base (x, file); |
| 1336 |
else if (GET_CODE (x) == PLUS) |
| 1337 |
{ |
| 1338 |
rtx x1, x2; |
| 1339 |
|
| 1340 |
x1 = XEXP (x, 0); |
| 1341 |
x2 = XEXP (x, 1); |
| 1342 |
if (cris_base_p (x1, true)) |
| 1343 |
{ |
| 1344 |
cris_print_base (x1, file); |
| 1345 |
cris_print_index (x2, file); |
| 1346 |
} |
| 1347 |
else if (cris_base_p (x2, true)) |
| 1348 |
{ |
| 1349 |
cris_print_base (x2, file); |
| 1350 |
cris_print_index (x1, file); |
| 1351 |
} |
| 1352 |
else |
| 1353 |
LOSE_AND_RETURN ("unrecognized address", x); |
| 1354 |
} |
| 1355 |
else if (MEM_P (x)) |
| 1356 |
{ |
| 1357 |
/* A DIP. Output more indirection characters. */ |
| 1358 |
putc ('[', file); |
| 1359 |
cris_print_base (XEXP (x, 0), file); |
| 1360 |
putc (']', file); |
| 1361 |
} |
| 1362 |
else |
| 1363 |
LOSE_AND_RETURN ("unrecognized address", x); |
| 1364 |
|
| 1365 |
putc (']', file); |
| 1366 |
} |
| 1367 |
|
| 1368 |
/* The RETURN_ADDR_RTX worker. |
| 1369 |
We mark that the return address is used, either by EH or |
| 1370 |
__builtin_return_address, for use by the function prologue and |
| 1371 |
epilogue. FIXME: This isn't optimal; we just use the mark in the |
| 1372 |
prologue and epilogue to say that the return address is to be stored |
| 1373 |
in the stack frame. We could return SRP for leaf-functions and use the |
| 1374 |
initial-value machinery. */ |
| 1375 |
|
| 1376 |
rtx |
| 1377 |
cris_return_addr_rtx (int count, rtx frameaddr ATTRIBUTE_UNUSED) |
| 1378 |
{ |
| 1379 |
cfun->machine->needs_return_address_on_stack = 1; |
| 1380 |
|
| 1381 |
/* The return-address is stored just above the saved frame-pointer (if |
| 1382 |
present). Apparently we can't eliminate from the frame-pointer in |
| 1383 |
that direction, so use the incoming args (maybe pretended) pointer. */ |
| 1384 |
return count == 0 |
| 1385 |
? gen_rtx_MEM (Pmode, plus_constant (Pmode, virtual_incoming_args_rtx, -4)) |
| 1386 |
: NULL_RTX; |
| 1387 |
} |
| 1388 |
|
| 1389 |
/* Setting the EH return return address is done by a *store* to a memory |
| 1390 |
address expressed as relative to "*incoming* args". That store will |
| 1391 |
be optimized away, unless the MEM is marked as volatile. N.B.: no |
| 1392 |
optimization opportunities are expected to be lost due to this hack; |
| 1393 |
__builtin_eh_return isn't called from elsewhere than the EH machinery |
| 1394 |
in libgcc. */ |
| 1395 |
|
| 1396 |
rtx |
| 1397 |
cris_eh_return_handler_rtx () |
| 1398 |
{ |
| 1399 |
rtx ret = cris_return_addr_rtx (0, NULL_RTX); |
| 1400 |
gcc_assert (MEM_P (ret)); |
| 1401 |
MEM_VOLATILE_P (ret) = true; |
| 1402 |
return ret; |
| 1403 |
} |
| 1404 |
|
| 1405 |
/* Accessor used in cris.md:return because cfun->machine isn't available |
| 1406 |
there. */ |
| 1407 |
|
| 1408 |
bool |
| 1409 |
cris_return_address_on_stack (void) |
| 1410 |
{ |
| 1411 |
return df_regs_ever_live_p (CRIS_SRP_REGNUM) |
| 1412 |
|| cfun->machine->needs_return_address_on_stack; |
| 1413 |
} |
| 1414 |
|
| 1415 |
/* Accessor used in cris.md:return because cfun->machine isn't available |
| 1416 |
there. */ |
| 1417 |
|
| 1418 |
bool |
| 1419 |
cris_return_address_on_stack_for_return (void) |
| 1420 |
{ |
| 1421 |
return cfun->machine->return_type == CRIS_RETINSN_RET ? false |
| 1422 |
: cris_return_address_on_stack (); |
| 1423 |
} |
| 1424 |
|
| 1425 |
/* This handles FP -> SP elimination offset. */ |
| 1426 |
|
| 1427 |
static int |
| 1428 |
cris_initial_frame_pointer_offset (void) |
| 1429 |
{ |
| 1430 |
int regno; |
| 1431 |
|
| 1432 |
/* Initial offset is 0 if we don't have a frame pointer. */ |
| 1433 |
int offs = 0; |
| 1434 |
|
| 1435 |
/* And 4 for each register pushed. */ |
| 1436 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 1437 |
if (cris_reg_saved_in_regsave_area (regno)) |
| 1438 |
offs += 4; |
| 1439 |
|
| 1440 |
/* And then, last, we add the locals allocated. */ |
| 1441 |
offs += get_frame_size (); |
| 1442 |
|
| 1443 |
/* And more; the accumulated args size. */ |
| 1444 |
offs += crtl->outgoing_args_size; |
| 1445 |
|
| 1446 |
/* Then round it off, in case we use aligned stack. */ |
| 1447 |
if (TARGET_STACK_ALIGN) |
| 1448 |
offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1; |
| 1449 |
|
| 1450 |
return offs; |
| 1451 |
} |
| 1452 |
|
| 1453 |
/* The INITIAL_ELIMINATION_OFFSET worker. |
| 1454 |
Calculate the difference between imaginary registers such as frame |
| 1455 |
pointer and the stack pointer. Used to eliminate the frame pointer |
| 1456 |
and imaginary arg pointer. */ |
| 1457 |
|
| 1458 |
int |
| 1459 |
cris_initial_elimination_offset (int fromreg, int toreg) |
| 1460 |
{ |
| 1461 |
int fp_sp_offset |
| 1462 |
= cris_initial_frame_pointer_offset (); |
| 1463 |
|
| 1464 |
/* We should be able to use regs_ever_live and related prologue |
| 1465 |
information here, or alpha should not as well. */ |
| 1466 |
bool return_address_on_stack = cris_return_address_on_stack (); |
| 1467 |
|
| 1468 |
/* Here we act as if the frame-pointer were needed. */ |
| 1469 |
int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0); |
| 1470 |
|
| 1471 |
if (fromreg == ARG_POINTER_REGNUM |
| 1472 |
&& toreg == HARD_FRAME_POINTER_REGNUM) |
| 1473 |
return ap_fp_offset; |
| 1474 |
|
| 1475 |
/* Between the frame pointer and the stack are only "normal" stack |
| 1476 |
variables and saved registers. */ |
| 1477 |
if (fromreg == FRAME_POINTER_REGNUM |
| 1478 |
&& toreg == STACK_POINTER_REGNUM) |
| 1479 |
return fp_sp_offset; |
| 1480 |
|
| 1481 |
/* We need to balance out the frame pointer here. */ |
| 1482 |
if (fromreg == ARG_POINTER_REGNUM |
| 1483 |
&& toreg == STACK_POINTER_REGNUM) |
| 1484 |
return ap_fp_offset + fp_sp_offset - 4; |
| 1485 |
|
| 1486 |
if (fromreg == FRAME_POINTER_REGNUM |
| 1487 |
&& toreg == HARD_FRAME_POINTER_REGNUM) |
| 1488 |
return 0; |
| 1489 |
|
| 1490 |
gcc_unreachable (); |
| 1491 |
} |
| 1492 |
|
| 1493 |
/* Nonzero if X is a hard reg that can be used as an index. */ |
| 1494 |
static inline bool |
| 1495 |
reg_ok_for_base_p (const_rtx x, bool strict) |
| 1496 |
{ |
| 1497 |
return ((! strict && ! HARD_REGISTER_P (x)) |
| 1498 |
|| REGNO_OK_FOR_BASE_P (REGNO (x))); |
| 1499 |
} |
| 1500 |
|
| 1501 |
/* Nonzero if X is a hard reg that can be used as an index. */ |
| 1502 |
static inline bool |
| 1503 |
reg_ok_for_index_p (const_rtx x, bool strict) |
| 1504 |
{ |
| 1505 |
return reg_ok_for_base_p (x, strict); |
| 1506 |
} |
| 1507 |
|
| 1508 |
/* True if X is a valid base register. */ |
| 1509 |
|
| 1510 |
bool |
| 1511 |
cris_base_p (const_rtx x, bool strict) |
| 1512 |
{ |
| 1513 |
return (REG_P (x) && reg_ok_for_base_p (x, strict)); |
| 1514 |
} |
| 1515 |
|
| 1516 |
/* True if X is a valid index register. */ |
| 1517 |
|
| 1518 |
static inline bool |
| 1519 |
cris_index_p (const_rtx x, bool strict) |
| 1520 |
{ |
| 1521 |
return (REG_P (x) && reg_ok_for_index_p (x, strict)); |
| 1522 |
} |
| 1523 |
|
| 1524 |
/* True if X is a valid base register with or without autoincrement. */ |
| 1525 |
|
| 1526 |
bool |
| 1527 |
cris_base_or_autoincr_p (const_rtx x, bool strict) |
| 1528 |
{ |
| 1529 |
return (cris_base_p (x, strict) |
| 1530 |
|| (GET_CODE (x) == POST_INC |
| 1531 |
&& cris_base_p (XEXP (x, 0), strict))); |
| 1532 |
} |
| 1533 |
|
| 1534 |
/* True if X is a valid (register) index for BDAP, i.e. [Rs].S or [Rs+].S. */ |
| 1535 |
|
| 1536 |
bool |
| 1537 |
cris_bdap_index_p (const_rtx x, bool strict) |
| 1538 |
{ |
| 1539 |
return ((MEM_P (x) |
| 1540 |
&& GET_MODE (x) == SImode |
| 1541 |
&& cris_base_or_autoincr_p (XEXP (x, 0), strict)) |
| 1542 |
|| (GET_CODE (x) == SIGN_EXTEND |
| 1543 |
&& MEM_P (XEXP (x, 0)) |
| 1544 |
&& (GET_MODE (XEXP (x, 0)) == HImode |
| 1545 |
|| GET_MODE (XEXP (x, 0)) == QImode) |
| 1546 |
&& cris_base_or_autoincr_p (XEXP (XEXP (x, 0), 0), strict))); |
| 1547 |
} |
| 1548 |
|
| 1549 |
/* True if X is a valid (register) index for BIAP, i.e. Rd.m. */ |
| 1550 |
|
| 1551 |
bool |
| 1552 |
cris_biap_index_p (const_rtx x, bool strict) |
| 1553 |
{ |
| 1554 |
return (cris_index_p (x, strict) |
| 1555 |
|| (GET_CODE (x) == MULT |
| 1556 |
&& cris_index_p (XEXP (x, 0), strict) |
| 1557 |
&& cris_scale_int_operand (XEXP (x, 1), VOIDmode))); |
| 1558 |
} |
| 1559 |
|
| 1560 |
/* Worker function for TARGET_LEGITIMATE_ADDRESS_P. */ |
| 1561 |
|
| 1562 |
static bool |
| 1563 |
cris_legitimate_address_p_hook (machine_mode mode, rtx x, bool strict, |
| 1564 |
code_helper) |
| 1565 |
{ |
| 1566 |
return cris_legitimate_address_p (mode, x, strict); |
| 1567 |
} |
| 1568 |
|
| 1569 |
bool |
| 1570 |
cris_legitimate_address_p (machine_mode mode, rtx x, bool strict) |
| 1571 |
{ |
| 1572 |
const_rtx x1, x2; |
| 1573 |
|
| 1574 |
if (cris_base_or_autoincr_p (x, strict)) |
| 1575 |
return true; |
| 1576 |
else if (CONSTANT_P (x)) |
| 1577 |
return true; |
| 1578 |
/* Indexed? */ |
| 1579 |
else if (GET_CODE (x) == PLUS) |
| 1580 |
{ |
| 1581 |
x1 = XEXP (x, 0); |
| 1582 |
x2 = XEXP (x, 1); |
| 1583 |
/* BDAP o, Rd. */ |
| 1584 |
if ((cris_base_p (x1, strict) && CONSTANT_P (x2)) |
| 1585 |
|| (cris_base_p (x2, strict) && CONSTANT_P (x1)) |
| 1586 |
/* BDAP Rs[+], Rd. */ |
| 1587 |
|| (GET_MODE_SIZE (mode) <= UNITS_PER_WORD |
| 1588 |
&& ((cris_base_p (x1, strict) |
| 1589 |
&& cris_bdap_index_p (x2, strict)) |
| 1590 |
|| (cris_base_p (x2, strict) |
| 1591 |
&& cris_bdap_index_p (x1, strict)) |
| 1592 |
/* BIAP.m Rs, Rd */ |
| 1593 |
|| (cris_base_p (x1, strict) |
| 1594 |
&& cris_biap_index_p (x2, strict)) |
| 1595 |
|| (cris_base_p (x2, strict) |
| 1596 |
&& cris_biap_index_p (x1, strict))))) |
| 1597 |
return true; |
| 1598 |
} |
| 1599 |
else if (MEM_P (x)) |
| 1600 |
{ |
| 1601 |
/* DIP (Rs). Reject [[reg+]] and [[reg]] for DImode (long long). */ |
| 1602 |
if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD |
| 1603 |
&& cris_base_or_autoincr_p (XEXP (x, 0), strict)) |
| 1604 |
return true; |
| 1605 |
} |
| 1606 |
|
| 1607 |
return false; |
| 1608 |
} |
| 1609 |
|
| 1610 |
/* Worker function for LEGITIMIZE_RELOAD_ADDRESS. */ |
| 1611 |
|
| 1612 |
bool |
| 1613 |
cris_reload_address_legitimized (rtx x, |
| 1614 |
machine_mode mode ATTRIBUTE_UNUSED, |
| 1615 |
int opnum ATTRIBUTE_UNUSED, |
| 1616 |
int itype, |
| 1617 |
int ind_levels ATTRIBUTE_UNUSED) |
| 1618 |
{ |
| 1619 |
enum reload_type type = (enum reload_type) itype; |
| 1620 |
rtx op0, op1; |
| 1621 |
rtx *op1p; |
| 1622 |
|
| 1623 |
if (GET_CODE (x) != PLUS) |
| 1624 |
return false; |
| 1625 |
|
| 1626 |
op0 = XEXP (x, 0); |
| 1627 |
op1 = XEXP (x, 1); |
| 1628 |
op1p = &XEXP (x, 1); |
| 1629 |
|
| 1630 |
if (!REG_P (op1)) |
| 1631 |
return false; |
| 1632 |
|
| 1633 |
if (GET_CODE (op0) == SIGN_EXTEND && MEM_P (XEXP (op0, 0))) |
| 1634 |
{ |
| 1635 |
rtx op00 = XEXP (op0, 0); |
| 1636 |
rtx op000 = XEXP (op00, 0); |
| 1637 |
rtx *op000p = &XEXP (op00, 0); |
| 1638 |
|
| 1639 |
if ((GET_MODE (op00) == HImode || GET_MODE (op00) == QImode) |
| 1640 |
&& (REG_P (op000) |
| 1641 |
|| (GET_CODE (op000) == POST_INC && REG_P (XEXP (op000, 0))))) |
| 1642 |
{ |
| 1643 |
bool something_reloaded = false; |
| 1644 |
|
| 1645 |
if (GET_CODE (op000) == POST_INC |
| 1646 |
&& REG_P (XEXP (op000, 0)) |
| 1647 |
&& REGNO (XEXP (op000, 0)) > CRIS_LAST_GENERAL_REGISTER) |
| 1648 |
/* No, this gets too complicated and is too rare to care |
| 1649 |
about trying to improve on the general code Here. |
| 1650 |
As the return-value is an all-or-nothing indicator, we |
| 1651 |
punt on the other register too. */ |
| 1652 |
return false; |
| 1653 |
|
| 1654 |
if ((REG_P (op000) |
| 1655 |
&& REGNO (op000) > CRIS_LAST_GENERAL_REGISTER)) |
| 1656 |
{ |
| 1657 |
/* The address of the inner mem is a pseudo or wrong |
| 1658 |
reg: reload that. */ |
| 1659 |
push_reload (op000, NULL_RTX, op000p, NULL, GENERAL_REGS, |
| 1660 |
GET_MODE (x), VOIDmode, 0, 0, opnum, type); |
| 1661 |
something_reloaded = true; |
| 1662 |
} |
| 1663 |
|
| 1664 |
if (REGNO (op1) > CRIS_LAST_GENERAL_REGISTER) |
| 1665 |
{ |
| 1666 |
/* Base register is a pseudo or wrong reg: reload it. */ |
| 1667 |
push_reload (op1, NULL_RTX, op1p, NULL, GENERAL_REGS, |
| 1668 |
GET_MODE (x), VOIDmode, 0, 0, |
| 1669 |
opnum, type); |
| 1670 |
something_reloaded = true; |
| 1671 |
} |
| 1672 |
|
| 1673 |
gcc_assert (something_reloaded); |
| 1674 |
|
| 1675 |
return true; |
| 1676 |
} |
| 1677 |
} |
| 1678 |
|
| 1679 |
return false; |
| 1680 |
} |
| 1681 |
|
| 1682 |
|
| 1683 |
/* Worker function for TARGET_PREFERRED_RELOAD_CLASS. |
| 1684 |
|
| 1685 |
It seems like gcc (2.7.2 and 2.9x of 2000-03-22) may send "NO_REGS" as |
| 1686 |
the class for a constant (testcase: __Mul in arit.c). To avoid forcing |
| 1687 |
out a constant into the constant pool, we will trap this case and |
| 1688 |
return something a bit more sane. FIXME: Check if this is a bug. |
| 1689 |
Beware that we must not "override" classes that can be specified as |
| 1690 |
constraint letters, or else asm operands using them will fail when |
| 1691 |
they need to be reloaded. FIXME: Investigate whether that constitutes |
| 1692 |
a bug. */ |
| 1693 |
|
| 1694 |
static reg_class_t |
| 1695 |
cris_preferred_reload_class (rtx x, reg_class_t rclass) |
| 1696 |
{ |
| 1697 |
if (rclass != MOF_REGS |
| 1698 |
&& rclass != MOF_SRP_REGS |
| 1699 |
&& rclass != SRP_REGS |
| 1700 |
&& rclass != CC0_REGS |
| 1701 |
&& rclass != SPECIAL_REGS) |
| 1702 |
return GENERAL_REGS; |
| 1703 |
|
| 1704 |
/* We can't make use of something that's not a general register when |
| 1705 |
reloading an "eliminated" register (i.e. something that has turned into |
| 1706 |
e.g. sp + const_int). */ |
| 1707 |
if (GET_CODE (x) == PLUS && !reg_class_subset_p (rclass, GENERAL_REGS)) |
| 1708 |
return NO_REGS; |
| 1709 |
|
| 1710 |
/* Avoid putting constants into a special register, where the instruction is |
| 1711 |
shorter if loaded into a general register. */ |
| 1712 |
if (satisfies_constraint_P (x) && !reg_class_subset_p (rclass, GENERAL_REGS)) |
| 1713 |
return NO_REGS; |
| 1714 |
|
| 1715 |
return rclass; |
| 1716 |
} |
| 1717 |
|
| 1718 |
/* Worker function for TARGET_SPILL_CLASS. */ |
| 1719 |
|
| 1720 |
static reg_class_t |
| 1721 |
cris_spill_class (reg_class_t /* orig_class */, machine_mode) |
| 1722 |
{ |
| 1723 |
return ALL_REGS; |
| 1724 |
} |
| 1725 |
|
| 1726 |
/* Worker function for TARGET_REGISTER_MOVE_COST. */ |
| 1727 |
|
| 1728 |
static int |
| 1729 |
cris_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED, |
| 1730 |
reg_class_t from, reg_class_t to) |
| 1731 |
{ |
| 1732 |
/* Can't move to and from a SPECIAL_REGS register, so we have to say |
| 1733 |
their move cost within that class is higher. How about 7? That's 3 |
| 1734 |
for a move to a GENERAL_REGS register, 3 for the move from the |
| 1735 |
GENERAL_REGS register, and 1 for the increased register pressure. |
| 1736 |
Also, it's higher than the memory move cost, as it should be. */ |
| 1737 |
|
| 1738 |
if (reg_classes_intersect_p (from, SPECIAL_REGS) |
| 1739 |
&& reg_classes_intersect_p (to, SPECIAL_REGS)) |
| 1740 |
return 7; |
| 1741 |
|
| 1742 |
/* Make moves to/from SPECIAL_REGS slightly more expensive, as we |
| 1743 |
generally prefer GENERAL_REGS. */ |
| 1744 |
if (reg_classes_intersect_p (from, SPECIAL_REGS) |
| 1745 |
|| reg_classes_intersect_p (to, SPECIAL_REGS)) |
| 1746 |
return 3; |
| 1747 |
|
| 1748 |
return 2; |
| 1749 |
} |
| 1750 |
|
| 1751 |
/* Worker function for TARGET_MEMORY_MOVE_COST. |
| 1752 |
|
| 1753 |
This isn't strictly correct for v0..3 in buswidth-8bit mode, but should |
| 1754 |
suffice. */ |
| 1755 |
|
| 1756 |
static int |
| 1757 |
cris_memory_move_cost (machine_mode mode, |
| 1758 |
reg_class_t rclass ATTRIBUTE_UNUSED, |
| 1759 |
bool in ATTRIBUTE_UNUSED) |
| 1760 |
{ |
| 1761 |
if (mode == QImode |
| 1762 |
|| mode == HImode) |
| 1763 |
return 4; |
| 1764 |
else |
| 1765 |
return 6; |
| 1766 |
} |
| 1767 |
|
| 1768 |
/* Worker function for SELECT_CC_MODE. */ |
| 1769 |
|
| 1770 |
machine_mode |
| 1771 |
cris_select_cc_mode (enum rtx_code op, rtx x, rtx y) |
| 1772 |
{ |
| 1773 |
/* We have different sets of patterns before and after |
| 1774 |
reload_completed, and everything before reload_completed is CCmode. |
| 1775 |
At the time of this writing, this function isn't called before that |
| 1776 |
time, so let's just gcc_assert on that assumption rather than doing |
| 1777 |
"if (!reload_completed) return CCmode;". */ |
| 1778 |
gcc_assert (reload_completed); |
| 1779 |
|
| 1780 |
/* For float mode or comparisons with something other than 0, we |
| 1781 |
always go with CCmode. */ |
| 1782 |
if (GET_MODE_CLASS (GET_MODE (x)) != MODE_INT || y != const0_rtx) |
| 1783 |
return CCmode; |
| 1784 |
|
| 1785 |
/* If we have a comparison that doesn't have to look at V or C, return |
| 1786 |
CC_NZmode. */ |
| 1787 |
if (op == EQ || op == NE || op == GTU || op == LEU |
| 1788 |
|| op == LT || op == GE) |
| 1789 |
return CC_NZmode; |
| 1790 |
|
| 1791 |
/* We should only get here for comparison operators. */ |
| 1792 |
gcc_assert (op == GEU || op == LTU || op == GT || op == LE); |
| 1793 |
|
| 1794 |
return CC_NZVCmode; |
| 1795 |
} |
| 1796 |
|
| 1797 |
/* Worker function for TARGET_CC_MODES_COMPATIBLE. |
| 1798 |
We start with CCmode for most comparisons, which merges and yields to |
| 1799 |
CC_NZmode or CC_NZVCmode. The exceptions have CC_NZVCmode and can't do with |
| 1800 |
another mode. */ |
| 1801 |
|
| 1802 |
static machine_mode |
| 1803 |
cris_cc_modes_compatible (machine_mode m1, machine_mode m2) |
| 1804 |
{ |
| 1805 |
if (m1 == CC_NZVCmode) |
| 1806 |
{ |
| 1807 |
if (m2 == CC_NZVCmode || m2 == CCmode) |
| 1808 |
return CC_NZVCmode; |
| 1809 |
return VOIDmode; |
| 1810 |
} |
| 1811 |
|
| 1812 |
if (m2 == CC_NZVCmode) |
| 1813 |
{ |
| 1814 |
if (m1 == CC_NZVCmode || m1 == CCmode) |
| 1815 |
return CC_NZVCmode; |
| 1816 |
return VOIDmode; |
| 1817 |
} |
| 1818 |
|
| 1819 |
if (m1 != m2) |
| 1820 |
return CC_NZmode; |
| 1821 |
|
| 1822 |
return m1; |
| 1823 |
} |
| 1824 |
|
| 1825 |
/* Return != 0 if the return sequence for the current function is short, |
| 1826 |
like "ret" or "jump [sp+]". Prior to reloading, we can't tell if |
| 1827 |
registers must be saved, so return 0 then. */ |
| 1828 |
|
| 1829 |
bool |
| 1830 |
cris_simple_epilogue (void) |
| 1831 |
{ |
| 1832 |
unsigned int regno; |
| 1833 |
unsigned int reglimit = STACK_POINTER_REGNUM; |
| 1834 |
|
| 1835 |
if (! reload_completed |
| 1836 |
|| frame_pointer_needed |
| 1837 |
|| get_frame_size () != 0 |
| 1838 |
|| crtl->args.pretend_args_size |
| 1839 |
|| crtl->args.size |
| 1840 |
|| crtl->outgoing_args_size |
| 1841 |
|| crtl->calls_eh_return |
| 1842 |
|
| 1843 |
/* If we're not supposed to emit prologue and epilogue, we must |
| 1844 |
not emit return-type instructions. */ |
| 1845 |
|| !TARGET_PROLOGUE_EPILOGUE) |
| 1846 |
return false; |
| 1847 |
|
| 1848 |
/* No simple epilogue if there are saved registers. */ |
| 1849 |
for (regno = 0; regno < reglimit; regno++) |
| 1850 |
if (cris_reg_saved_in_regsave_area (regno)) |
| 1851 |
return false; |
| 1852 |
|
| 1853 |
return true; |
| 1854 |
} |
| 1855 |
|
| 1856 |
/* Emit checking that MEM is aligned for an access in MODE, failing |
| 1857 |
that, executing a "break 8" (or call to abort, if "break 8" is |
| 1858 |
disabled). */ |
| 1859 |
|
| 1860 |
void |
| 1861 |
cris_emit_trap_for_misalignment (rtx mem) |
| 1862 |
{ |
| 1863 |
rtx addr, reg, ok_label, andop; |
| 1864 |
rtx_insn *jmp; |
| 1865 |
int natural_alignment; |
| 1866 |
gcc_assert (MEM_P (mem)); |
| 1867 |
|
| 1868 |
natural_alignment = GET_MODE_SIZE (GET_MODE (mem)); |
| 1869 |
addr = XEXP (mem, 0); |
| 1870 |
reg = force_reg (Pmode, addr); |
| 1871 |
ok_label = gen_label_rtx (); |
| 1872 |
|
| 1873 |
/* This will yield a btstq without a separate register used, usually - |
| 1874 |
with the exception for PRE hoisting the "and" but not the branch |
| 1875 |
around the trap: see testsuite/gcc.target/cris/sync-3s.c. */ |
| 1876 |
andop = gen_rtx_AND (Pmode, reg, GEN_INT (natural_alignment - 1)); |
| 1877 |
emit_cmp_and_jump_insns (force_reg (SImode, andop), const0_rtx, EQ, |
| 1878 |
NULL_RTX, Pmode, 1, ok_label); |
| 1879 |
jmp = get_last_insn (); |
| 1880 |
gcc_assert (JUMP_P (jmp)); |
| 1881 |
|
| 1882 |
predict_insn_def (jmp, PRED_NORETURN, TAKEN); |
| 1883 |
expand_builtin_trap (); |
| 1884 |
emit_label (ok_label); |
| 1885 |
} |
| 1886 |
|
| 1887 |
/* Expand a return insn (just one insn) marked as using SRP or stack |
| 1888 |
slot depending on parameter ON_STACK. */ |
| 1889 |
|
| 1890 |
void |
| 1891 |
cris_expand_return (bool on_stack) |
| 1892 |
{ |
| 1893 |
/* FIXME: emit a parallel with a USE for SRP or the stack-slot, to |
| 1894 |
tell "ret" from "jump [sp+]". Some, but not all, other parts of |
| 1895 |
GCC expect just (return) to do the right thing when optimizing, so |
| 1896 |
we do that until they're fixed. Currently, all return insns in a |
| 1897 |
function must be the same (not really a limiting factor) so we need |
| 1898 |
to check that it doesn't change half-way through. */ |
| 1899 |
emit_jump_insn (ret_rtx); |
| 1900 |
|
| 1901 |
CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_RET || !on_stack); |
| 1902 |
CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_JUMP || on_stack); |
| 1903 |
|
| 1904 |
cfun->machine->return_type |
| 1905 |
= on_stack ? CRIS_RETINSN_JUMP : CRIS_RETINSN_RET; |
| 1906 |
} |
| 1907 |
|
| 1908 |
/* Compute a (partial) cost for rtx X. Return true if the complete |
| 1909 |
cost has been computed, and false if subexpressions should be |
| 1910 |
scanned. In either case, *TOTAL contains the cost result. */ |
| 1911 |
|
| 1912 |
static bool |
| 1913 |
cris_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno, |
| 1914 |
int *total, bool speed) |
| 1915 |
{ |
| 1916 |
int code = GET_CODE (x); |
| 1917 |
|
| 1918 |
switch (code) |
| 1919 |
{ |
| 1920 |
case CONST_INT: |
| 1921 |
{ |
| 1922 |
HOST_WIDE_INT val = INTVAL (x); |
| 1923 |
if (val == 0) |
| 1924 |
*total = 0; |
| 1925 |
else if (val < 32 && val >= -32) |
| 1926 |
switch (outer_code) |
| 1927 |
{ |
| 1928 |
/* For modes that fit in one register we tell they cost |
| 1929 |
the same as with register operands. DImode operations |
| 1930 |
needs careful consideration for more basic reasons: |
| 1931 |
shifting by a non-word-size amount needs more |
| 1932 |
operations than an addition by a register pair. |
| 1933 |
Deliberately excluding SET, PLUS and comparisons and |
| 1934 |
also not including the full -64..63 range for (PLUS |
| 1935 |
and) MINUS. */ |
| 1936 |
case MINUS: case ASHIFT: case LSHIFTRT: |
| 1937 |
case ASHIFTRT: case AND: case IOR: |
| 1938 |
if (GET_MODE_SIZE(mode) <= UNITS_PER_WORD) |
| 1939 |
{ |
| 1940 |
*total = 0; |
| 1941 |
break; |
| 1942 |
} |
| 1943 |
/* FALL THROUGH. */ |
| 1944 |
default: |
| 1945 |
*total = 1; |
| 1946 |
break; |
| 1947 |
} |
| 1948 |
/* Eight or 16 bits are a word and cycle more expensive. */ |
| 1949 |
else if (val <= 32767 && val >= -32768) |
| 1950 |
*total = 2; |
| 1951 |
/* A 32-bit constant (or very seldom, unsigned 16 bits) costs |
| 1952 |
another word. FIXME: This isn't linear to 16 bits. */ |
| 1953 |
else |
| 1954 |
*total = 4; |
| 1955 |
return true; |
| 1956 |
} |
| 1957 |
|
| 1958 |
case LABEL_REF: |
| 1959 |
*total = 6; |
| 1960 |
return true; |
| 1961 |
|
| 1962 |
case CONST: |
| 1963 |
case SYMBOL_REF: |
| 1964 |
*total = 6; |
| 1965 |
return true; |
| 1966 |
|
| 1967 |
case CONST_DOUBLE: |
| 1968 |
if (x != CONST0_RTX (mode == VOIDmode ? DImode : mode)) |
| 1969 |
*total = 12; |
| 1970 |
else |
| 1971 |
/* Make 0.0 cheap, else test-insns will not be used. */ |
| 1972 |
*total = 0; |
| 1973 |
return true; |
| 1974 |
|
| 1975 |
case MULT: |
| 1976 |
/* If we have one arm of an ADDI, make sure it gets the cost of |
| 1977 |
one insn, i.e. zero cost for this operand, and just the cost |
| 1978 |
of the PLUS, as the insn is created by combine from a PLUS |
| 1979 |
and an ASHIFT, and the MULT cost below would make the |
| 1980 |
combined value be larger than the separate insns. The insn |
| 1981 |
validity is checked elsewhere by combine. |
| 1982 |
|
| 1983 |
FIXME: this case is a stop-gap for 4.3 and 4.4, this whole |
| 1984 |
function should be rewritten. */ |
| 1985 |
if (outer_code == PLUS && cris_biap_index_p (x, false)) |
| 1986 |
{ |
| 1987 |
*total = 0; |
| 1988 |
return true; |
| 1989 |
} |
| 1990 |
|
| 1991 |
/* Identify values that are no powers of two. Powers of 2 are |
| 1992 |
taken care of already and those values should not be changed. */ |
| 1993 |
if (!CONST_INT_P (XEXP (x, 1)) |
| 1994 |
|| exact_log2 (INTVAL (XEXP (x, 1)) < 0)) |
| 1995 |
{ |
| 1996 |
/* If we have a multiply insn, then the cost is between |
| 1997 |
1 and 2 "fast" instructions. */ |
| 1998 |
if (TARGET_HAS_MUL_INSNS) |
| 1999 |
{ |
| 2000 |
*total = COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2; |
| 2001 |
return true; |
| 2002 |
} |
| 2003 |
|
| 2004 |
/* Estimate as 4 + 4 * #ofbits. */ |
| 2005 |
*total = COSTS_N_INSNS (132); |
| 2006 |
return true; |
| 2007 |
} |
| 2008 |
return false; |
| 2009 |
|
| 2010 |
case UDIV: |
| 2011 |
case MOD: |
| 2012 |
case UMOD: |
| 2013 |
case DIV: |
| 2014 |
if (!CONST_INT_P (XEXP (x, 1)) |
| 2015 |
|| exact_log2 (INTVAL (XEXP (x, 1)) < 0)) |
| 2016 |
{ |
| 2017 |
/* Estimate this as 4 + 8 * #of bits. */ |
| 2018 |
*total = COSTS_N_INSNS (260); |
| 2019 |
return true; |
| 2020 |
} |
| 2021 |
return false; |
| 2022 |
|
| 2023 |
case AND: |
| 2024 |
if (CONST_INT_P (XEXP (x, 1)) |
| 2025 |
/* Two constants may actually happen before optimization. */ |
| 2026 |
&& !CONST_INT_P (XEXP (x, 0)) |
| 2027 |
&& !satisfies_constraint_I (XEXP (x, 1))) |
| 2028 |
{ |
| 2029 |
*total |
| 2030 |
= (rtx_cost (XEXP (x, 0), mode, (enum rtx_code) outer_code, |
| 2031 |
opno, speed) + 2 |
| 2032 |
+ 2 * GET_MODE_NUNITS (mode)); |
| 2033 |
return true; |
| 2034 |
} |
| 2035 |
return false; |
| 2036 |
|
| 2037 |
case ZERO_EXTRACT: |
| 2038 |
/* Conditionals are split after reload, giving a different look. */ |
| 2039 |
if (reload_completed) |
| 2040 |
{ |
| 2041 |
if (outer_code != COMPARE) |
| 2042 |
return false; |
| 2043 |
} |
| 2044 |
else |
| 2045 |
switch (outer_code) |
| 2046 |
{ |
| 2047 |
case EQ: |
| 2048 |
case NE: |
| 2049 |
case LT: |
| 2050 |
case LTU: |
| 2051 |
case LE: |
| 2052 |
case LEU: |
| 2053 |
case GT: |
| 2054 |
case GTU: |
| 2055 |
case GE: |
| 2056 |
case GEU: |
| 2057 |
break; |
| 2058 |
|
| 2059 |
default: |
| 2060 |
return false; |
| 2061 |
} |
| 2062 |
/* fall through */ |
| 2063 |
|
| 2064 |
case ZERO_EXTEND: case SIGN_EXTEND: |
| 2065 |
*total = rtx_cost (XEXP (x, 0), VOIDmode, (enum rtx_code) outer_code, |
| 2066 |
opno, speed); |
| 2067 |
return true; |
| 2068 |
|
| 2069 |
default: |
| 2070 |
return false; |
| 2071 |
} |
| 2072 |
} |
| 2073 |
|
| 2074 |
/* The ADDRESS_COST worker. */ |
| 2075 |
|
| 2076 |
static int |
| 2077 |
cris_address_cost (rtx x, machine_mode mode ATTRIBUTE_UNUSED, |
| 2078 |
addr_space_t as ATTRIBUTE_UNUSED, |
| 2079 |
bool speed ATTRIBUTE_UNUSED) |
| 2080 |
{ |
| 2081 |
/* The metric to use for the cost-macros is unclear. |
| 2082 |
The metric used here is (the number of cycles needed) / 2, |
| 2083 |
where we consider equal a cycle for a word of code and a cycle to |
| 2084 |
read memory. FIXME: Adding "+ 1" to all values would avoid |
| 2085 |
returning 0, as tree-ssa-loop-ivopts.cc as of r128272 "normalizes" |
| 2086 |
0 to 1, thereby giving equal costs to [rN + rM] and [rN]. |
| 2087 |
Unfortunately(?) such a hack would expose other pessimizations, |
| 2088 |
at least with g++.dg/tree-ssa/ivopts-1.C, adding insns to the |
| 2089 |
loop there, without apparent reason. */ |
| 2090 |
|
| 2091 |
/* The cheapest addressing modes get 0, since nothing extra is needed. */ |
| 2092 |
if (cris_base_or_autoincr_p (x, false)) |
| 2093 |
return 0; |
| 2094 |
|
| 2095 |
/* An indirect mem must be a DIP. This means two bytes extra for code, |
| 2096 |
and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */ |
| 2097 |
if (MEM_P (x)) |
| 2098 |
return (2 + 4) / 2; |
| 2099 |
|
| 2100 |
/* Assume (2 + 4) / 2 for a single constant; a dword, since it needs |
| 2101 |
an extra DIP prefix and 4 bytes of constant in most cases. */ |
| 2102 |
if (CONSTANT_P (x)) |
| 2103 |
return (2 + 4) / 2; |
| 2104 |
|
| 2105 |
/* Handle BIAP and BDAP prefixes. */ |
| 2106 |
if (GET_CODE (x) == PLUS) |
| 2107 |
{ |
| 2108 |
rtx tem1 = XEXP (x, 0); |
| 2109 |
rtx tem2 = XEXP (x, 1); |
| 2110 |
|
| 2111 |
/* Local extended canonicalization rule: the first operand must |
| 2112 |
be REG, unless it's an operation (MULT). */ |
| 2113 |
if (!REG_P (tem1) && GET_CODE (tem1) != MULT) |
| 2114 |
tem1 = tem2, tem2 = XEXP (x, 0); |
| 2115 |
|
| 2116 |
/* We'll "assume" we have canonical RTX now. */ |
| 2117 |
gcc_assert (REG_P (tem1) || GET_CODE (tem1) == MULT); |
| 2118 |
|
| 2119 |
/* A BIAP is 2 extra bytes for the prefix insn, nothing more. We |
| 2120 |
recognize the typical MULT which is always in tem1 because of |
| 2121 |
insn canonicalization. */ |
| 2122 |
if ((GET_CODE (tem1) == MULT && cris_biap_index_p (tem1, false)) |
| 2123 |
|| REG_P (tem2)) |
| 2124 |
return 2 / 2; |
| 2125 |
|
| 2126 |
/* A BDAP (quick) is 2 extra bytes. Any constant operand to the |
| 2127 |
PLUS is always found in tem2. */ |
| 2128 |
if (CONST_INT_P (tem2) && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128) |
| 2129 |
return 2 / 2; |
| 2130 |
|
| 2131 |
/* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra |
| 2132 |
bytes. */ |
| 2133 |
if (satisfies_constraint_L (tem2)) |
| 2134 |
return (2 + 2) / 2; |
| 2135 |
|
| 2136 |
/* A BDAP with some other constant is 2 bytes extra. */ |
| 2137 |
if (CONSTANT_P (tem2)) |
| 2138 |
return (2 + 2 + 2) / 2; |
| 2139 |
|
| 2140 |
/* BDAP with something indirect should have a higher cost than |
| 2141 |
BIAP with register. FIXME: Should it cost like a MEM or more? */ |
| 2142 |
return (2 + 2 + 2) / 2; |
| 2143 |
} |
| 2144 |
|
| 2145 |
/* What else? Return a high cost. It matters only for valid |
| 2146 |
addressing modes. */ |
| 2147 |
return 10; |
| 2148 |
} |
| 2149 |
|
| 2150 |
/* Check various objections to the side-effect. Used in the test-part |
| 2151 |
of an anonymous insn describing an insn with a possible side-effect. |
| 2152 |
Returns nonzero if the implied side-effect is ok. |
| 2153 |
|
| 2154 |
code : PLUS or MULT |
| 2155 |
ops : An array of rtx:es. lreg, rreg, rval, |
| 2156 |
The variables multop and other_op are indexes into this, |
| 2157 |
or -1 if they are not applicable. |
| 2158 |
lreg : The register that gets assigned in the side-effect. |
| 2159 |
rreg : One register in the side-effect expression |
| 2160 |
rval : The other register, or an int. |
| 2161 |
multop : An integer to multiply rval with. |
| 2162 |
other_op : One of the entities of the main effect, |
| 2163 |
whose mode we must consider. */ |
| 2164 |
|
| 2165 |
int |
| 2166 |
cris_side_effect_mode_ok (enum rtx_code code, rtx *ops, |
| 2167 |
int lreg, int rreg, int rval, |
| 2168 |
int multop, int other_op) |
| 2169 |
{ |
| 2170 |
/* Find what value to multiply with, for rx =ry + rz * n. */ |
| 2171 |
int mult = multop < 0 ? 1 : INTVAL (ops[multop]); |
| 2172 |
|
| 2173 |
rtx reg_rtx = ops[rreg]; |
| 2174 |
rtx val_rtx = ops[rval]; |
| 2175 |
|
| 2176 |
/* The operands may be swapped. Canonicalize them in reg_rtx and |
| 2177 |
val_rtx, where reg_rtx always is a reg (for this constraint to |
| 2178 |
match). */ |
| 2179 |
if (! cris_base_p (reg_rtx, lra_in_progress || reload_completed)) |
| 2180 |
reg_rtx = val_rtx, val_rtx = ops[rreg]; |
| 2181 |
|
| 2182 |
/* Don't forget to check that reg_rtx really is a reg. If it isn't, |
| 2183 |
we have no business. */ |
| 2184 |
if (! cris_base_p (reg_rtx, lra_in_progress || reload_completed)) |
| 2185 |
return 0; |
| 2186 |
|
| 2187 |
/* Don't do this when -mno-split. */ |
| 2188 |
if (!TARGET_SIDE_EFFECT_PREFIXES) |
| 2189 |
return 0; |
| 2190 |
|
| 2191 |
/* The mult expression may be hidden in lreg. FIXME: Add more |
| 2192 |
commentary about that. */ |
| 2193 |
if (GET_CODE (val_rtx) == MULT) |
| 2194 |
{ |
| 2195 |
mult = INTVAL (XEXP (val_rtx, 1)); |
| 2196 |
val_rtx = XEXP (val_rtx, 0); |
| 2197 |
code = MULT; |
| 2198 |
} |
| 2199 |
|
| 2200 |
/* First check the "other operand". */ |
| 2201 |
if (other_op >= 0) |
| 2202 |
{ |
| 2203 |
if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD) |
| 2204 |
return 0; |
| 2205 |
|
| 2206 |
/* Check if the lvalue register is the same as the "other |
| 2207 |
operand". If so, the result is undefined and we shouldn't do |
| 2208 |
this. FIXME: Check again. */ |
| 2209 |
if ((cris_base_p (ops[lreg], lra_in_progress || reload_completed) |
| 2210 |
&& cris_base_p (ops[other_op], |
| 2211 |
lra_in_progress || reload_completed) |
| 2212 |
&& REGNO (ops[lreg]) == REGNO (ops[other_op])) |
| 2213 |
|| rtx_equal_p (ops[other_op], ops[lreg])) |
| 2214 |
return 0; |
| 2215 |
} |
| 2216 |
|
| 2217 |
/* Do not accept frame_pointer_rtx as any operand. */ |
| 2218 |
if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx |
| 2219 |
|| ops[rval] == frame_pointer_rtx |
| 2220 |
|| (other_op >= 0 && ops[other_op] == frame_pointer_rtx)) |
| 2221 |
return 0; |
| 2222 |
|
| 2223 |
if (code == PLUS |
| 2224 |
&& ! cris_base_p (val_rtx, lra_in_progress || reload_completed)) |
| 2225 |
{ |
| 2226 |
|
| 2227 |
/* Do not allow rx = rx + n if a normal add or sub with same size |
| 2228 |
would do. */ |
| 2229 |
if (rtx_equal_p (ops[lreg], reg_rtx) |
| 2230 |
&& CONST_INT_P (val_rtx) |
| 2231 |
&& (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63)) |
| 2232 |
return 0; |
| 2233 |
|
| 2234 |
/* Check allowed cases, like [r(+)?].[bwd] and const. */ |
| 2235 |
if (CONSTANT_P (val_rtx)) |
| 2236 |
return 1; |
| 2237 |
|
| 2238 |
if (MEM_P (val_rtx) |
| 2239 |
&& cris_base_or_autoincr_p (XEXP (val_rtx, 0), |
| 2240 |
lra_in_progress || reload_completed)) |
| 2241 |
return 1; |
| 2242 |
|
| 2243 |
if (GET_CODE (val_rtx) == SIGN_EXTEND |
| 2244 |
&& MEM_P (XEXP (val_rtx, 0)) |
| 2245 |
&& cris_base_or_autoincr_p (XEXP (XEXP (val_rtx, 0), 0), |
| 2246 |
lra_in_progress || reload_completed)) |
| 2247 |
return 1; |
| 2248 |
|
| 2249 |
/* If we got here, it's not a valid addressing mode. */ |
| 2250 |
return 0; |
| 2251 |
} |
| 2252 |
else if (code == MULT |
| 2253 |
|| (code == PLUS |
| 2254 |
&& cris_base_p (val_rtx, |
| 2255 |
lra_in_progress || reload_completed))) |
| 2256 |
{ |
| 2257 |
/* Do not allow rx = rx + ry.S, since it doesn't give better code. */ |
| 2258 |
if (rtx_equal_p (ops[lreg], reg_rtx) |
| 2259 |
|| (mult == 1 && rtx_equal_p (ops[lreg], val_rtx))) |
| 2260 |
return 0; |
| 2261 |
|
| 2262 |
/* Do not allow bad multiply-values. */ |
| 2263 |
if (mult != 1 && mult != 2 && mult != 4) |
| 2264 |
return 0; |
| 2265 |
|
| 2266 |
/* Only allow r + ... */ |
| 2267 |
if (! cris_base_p (reg_rtx, lra_in_progress || reload_completed)) |
| 2268 |
return 0; |
| 2269 |
|
| 2270 |
/* If we got here, all seems ok. |
| 2271 |
(All checks need to be done above). */ |
| 2272 |
return 1; |
| 2273 |
} |
| 2274 |
|
| 2275 |
/* If we get here, the caller got its initial tests wrong. */ |
| 2276 |
internal_error ("internal error: %<cris_side_effect_mode_ok%> with bad operands"); |
| 2277 |
} |
| 2278 |
|
| 2279 |
/* Queue an .ident string in the queue of top-level asm statements. |
| 2280 |
If the front-end is done, we must be being called from toplev.cc. |
| 2281 |
In that case, do nothing. */ |
| 2282 |
void |
| 2283 |
cris_asm_output_ident (const char *string) |
| 2284 |
{ |
| 2285 |
if (symtab->state != PARSING) |
| 2286 |
return; |
| 2287 |
|
| 2288 |
default_asm_output_ident_directive (string); |
| 2289 |
} |
| 2290 |
|
| 2291 |
/* The ASM_OUTPUT_CASE_END worker. */ |
| 2292 |
|
| 2293 |
void |
| 2294 |
cris_asm_output_case_end (FILE *stream, int num, rtx_insn *table) |
| 2295 |
{ |
| 2296 |
/* Step back, over the label for the table, to the actual casejump and |
| 2297 |
assert that we find only what's expected. */ |
| 2298 |
rtx_insn *whole_jump_insn = prev_nonnote_nondebug_insn (table); |
| 2299 |
gcc_assert (whole_jump_insn != NULL_RTX && LABEL_P (whole_jump_insn)); |
| 2300 |
|
| 2301 |
whole_jump_insn = prev_nonnote_nondebug_insn (whole_jump_insn); |
| 2302 |
gcc_assert (whole_jump_insn != NULL_RTX && JUMP_P (whole_jump_insn)); |
| 2303 |
|
| 2304 |
/* Get the pattern of the casejump, so we can extract the default label. */ |
| 2305 |
rtx whole_jump_pat = PATTERN (whole_jump_insn); |
| 2306 |
|
| 2307 |
asm_fprintf (stream, |
| 2308 |
"\t.word %LL%d-%LL%d%s\n", |
| 2309 |
CODE_LABEL_NUMBER (XEXP |
| 2310 |
(XEXP |
| 2311 |
(XEXP (XVECEXP (whole_jump_pat, 0, 0), 1), |
| 2312 |
2), 0)), |
| 2313 |
num, |
| 2314 |
(TARGET_PDEBUG ? "; default" : "")); |
| 2315 |
} |
| 2316 |
|
| 2317 |
/* The TARGET_OPTION_OVERRIDE worker. |
| 2318 |
As is the norm, this also parses -mfoo=bar type parameters. */ |
| 2319 |
|
| 2320 |
static void |
| 2321 |
cris_option_override (void) |
| 2322 |
{ |
| 2323 |
if (cris_max_stackframe_str) |
| 2324 |
{ |
| 2325 |
cris_max_stackframe = atoi (cris_max_stackframe_str); |
| 2326 |
|
| 2327 |
/* Do some sanity checking. */ |
| 2328 |
if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000) |
| 2329 |
internal_error ("%<-max-stackframe=%d%> is not usable, " |
| 2330 |
"not between 0 and %d", |
| 2331 |
cris_max_stackframe, 0x20000000); |
| 2332 |
} |
| 2333 |
|
| 2334 |
/* Let "-metrax4" and "-metrax100" change the cpu version. */ |
| 2335 |
if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO) |
| 2336 |
cris_cpu_version = CRIS_CPU_SVINTO; |
| 2337 |
else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4) |
| 2338 |
cris_cpu_version = CRIS_CPU_ETRAX4; |
| 2339 |
|
| 2340 |
/* Parse -march=... and its synonym, the deprecated -mcpu=... */ |
| 2341 |
if (cris_cpu_str) |
| 2342 |
{ |
| 2343 |
cris_cpu_version |
| 2344 |
= (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1); |
| 2345 |
|
| 2346 |
if (strcmp ("etrax4", cris_cpu_str) == 0) |
| 2347 |
cris_cpu_version = 3; |
| 2348 |
|
| 2349 |
if (strcmp ("svinto", cris_cpu_str) == 0 |
| 2350 |
|| strcmp ("etrax100", cris_cpu_str) == 0) |
| 2351 |
cris_cpu_version = 8; |
| 2352 |
|
| 2353 |
if (strcmp ("ng", cris_cpu_str) == 0 |
| 2354 |
|| strcmp ("etrax100lx", cris_cpu_str) == 0) |
| 2355 |
cris_cpu_version = 10; |
| 2356 |
|
| 2357 |
if (cris_cpu_version < 0 || cris_cpu_version > 10) |
| 2358 |
error ("unknown CRIS version specification in %<-march=%> or " |
| 2359 |
"%<-mcpu=%>: %s", cris_cpu_str); |
| 2360 |
|
| 2361 |
/* Set the target flags. */ |
| 2362 |
if (cris_cpu_version >= CRIS_CPU_ETRAX4) |
| 2363 |
target_flags |= MASK_ETRAX4_ADD; |
| 2364 |
|
| 2365 |
/* If this is Svinto or higher, align for 32 bit accesses. */ |
| 2366 |
if (cris_cpu_version >= CRIS_CPU_SVINTO) |
| 2367 |
target_flags |
| 2368 |
|= (MASK_SVINTO | MASK_ALIGN_BY_32 |
| 2369 |
| MASK_STACK_ALIGN | MASK_CONST_ALIGN |
| 2370 |
| MASK_DATA_ALIGN); |
| 2371 |
|
| 2372 |
/* Note that we do not add new flags when it can be completely |
| 2373 |
described with a macro that uses -mcpu=X. So |
| 2374 |
TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */ |
| 2375 |
} |
| 2376 |
|
| 2377 |
if (cris_tune_str) |
| 2378 |
{ |
| 2379 |
int cris_tune |
| 2380 |
= (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1); |
| 2381 |
|
| 2382 |
if (strcmp ("etrax4", cris_tune_str) == 0) |
| 2383 |
cris_tune = 3; |
| 2384 |
|
| 2385 |
if (strcmp ("svinto", cris_tune_str) == 0 |
| 2386 |
|| strcmp ("etrax100", cris_tune_str) == 0) |
| 2387 |
cris_tune = 8; |
| 2388 |
|
| 2389 |
if (strcmp ("ng", cris_tune_str) == 0 |
| 2390 |
|| strcmp ("etrax100lx", cris_tune_str) == 0) |
| 2391 |
cris_tune = 10; |
| 2392 |
|
| 2393 |
if (cris_tune < 0 || cris_tune > 32) |
| 2394 |
error ("unknown CRIS cpu version specification in %<-mtune=%>: %s", |
| 2395 |
cris_tune_str); |
| 2396 |
|
| 2397 |
if (cris_tune >= CRIS_CPU_SVINTO) |
| 2398 |
/* We have currently nothing more to tune than alignment for |
| 2399 |
memory accesses. */ |
| 2400 |
target_flags |
| 2401 |
|= (MASK_STACK_ALIGN | MASK_CONST_ALIGN |
| 2402 |
| MASK_DATA_ALIGN | MASK_ALIGN_BY_32); |
| 2403 |
} |
| 2404 |
|
| 2405 |
if (flag_pic) |
| 2406 |
{ |
| 2407 |
/* Use error rather than warning, so invalid use is easily |
| 2408 |
detectable. Still change to the values we expect, to avoid |
| 2409 |
further errors. */ |
| 2410 |
error ("%<-fPIC%> and %<-fpic%> are not supported on this target"); |
| 2411 |
flag_pic = 0; |
| 2412 |
} |
| 2413 |
|
| 2414 |
/* Set the per-function-data initializer. */ |
| 2415 |
init_machine_status = cris_init_machine_status; |
| 2416 |
|
| 2417 |
cris_option_override_after_change (); |
| 2418 |
} |
| 2419 |
|
| 2420 |
/* The TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE worker. |
| 2421 |
|
| 2422 |
The CRIS port doesn't have any port-specific function attributes to |
| 2423 |
handle, but to keep attributes consistent across per-function changes |
| 2424 |
and not fail per-function optimization settings as exposed by |
| 2425 |
gcc.dg/ipa/iinline-attr.c, any OPTION_SET_P work need to be done |
| 2426 |
here, not in the TARGET_OPTION_OVERRIDE function. This function then |
| 2427 |
instead needs to called from that function. */ |
| 2428 |
|
| 2429 |
static void |
| 2430 |
cris_option_override_after_change () |
| 2431 |
{ |
| 2432 |
/* The combine pass inserts extra copies of the incoming parameter |
| 2433 |
registers in make_more_copies, between the hard registers and |
| 2434 |
pseudo-registers holding the "original" copies. When doing that, |
| 2435 |
it does not copy attributes from those original registers. With |
| 2436 |
the late-combine pass, those extra copies are propagated into more |
| 2437 |
places than the original copies, and trips up LRA which doesn't see |
| 2438 |
e.g. REG_POINTER where it's expected. This causes an ICE for |
| 2439 |
gcc.target/cris/rld-legit1.c. That's a red flag, but also a very |
| 2440 |
special corner case. |
| 2441 |
|
| 2442 |
A more valid reason is that coremark with -march=v10 -O2 regresses |
| 2443 |
by 2.6% @r15-2005-g13757e50ff0b compared to late-combined disabled. |
| 2444 |
|
| 2445 |
Disable late-combine by default until that's fixed. */ |
| 2446 |
if (!OPTION_SET_P (flag_late_combine_instructions)) |
| 2447 |
flag_late_combine_instructions = 0; |
| 2448 |
} |
| 2449 |
|
| 2450 |
/* The TARGET_ASM_OUTPUT_MI_THUNK worker. */ |
| 2451 |
|
| 2452 |
static void |
| 2453 |
cris_asm_output_mi_thunk (FILE *stream, |
| 2454 |
tree thunkdecl ATTRIBUTE_UNUSED, |
| 2455 |
HOST_WIDE_INT delta, |
| 2456 |
HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED, |
| 2457 |
tree funcdecl) |
| 2458 |
{ |
| 2459 |
const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunkdecl)); |
| 2460 |
|
| 2461 |
assemble_start_function (thunkdecl, fnname); |
| 2462 |
/* Make sure unwind info is emitted for the thunk if needed. */ |
| 2463 |
final_start_function (emit_barrier (), stream, 1); |
| 2464 |
|
| 2465 |
if (delta > 0) |
| 2466 |
fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n", |
| 2467 |
ADDITIVE_SIZE_MODIFIER (delta), delta, |
| 2468 |
reg_names[CRIS_FIRST_ARG_REG]); |
| 2469 |
else if (delta < 0) |
| 2470 |
fprintf (stream, "\tsub%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n", |
| 2471 |
ADDITIVE_SIZE_MODIFIER (-delta), -delta, |
| 2472 |
reg_names[CRIS_FIRST_ARG_REG]); |
| 2473 |
|
| 2474 |
fprintf (stream, "\tjump "); |
| 2475 |
assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0)); |
| 2476 |
fprintf (stream, "\n"); |
| 2477 |
|
| 2478 |
final_end_function (); |
| 2479 |
assemble_end_function (thunkdecl, fnname); |
| 2480 |
} |
| 2481 |
|
| 2482 |
/* Boilerplate emitted at start of file. |
| 2483 |
|
| 2484 |
NO_APP *only at file start* means faster assembly. It also means |
| 2485 |
comments are not allowed. In some cases comments will be output |
| 2486 |
for debugging purposes. Make sure they are allowed then. */ |
| 2487 |
static void |
| 2488 |
cris_file_start (void) |
| 2489 |
{ |
| 2490 |
/* These expressions can vary at run time, so we cannot put |
| 2491 |
them into TARGET_INITIALIZER. */ |
| 2492 |
targetm.asm_file_start_app_off = !(TARGET_PDEBUG || flag_print_asm_name); |
| 2493 |
|
| 2494 |
default_file_start (); |
| 2495 |
} |
| 2496 |
|
| 2497 |
/* Rename the function calls for integer multiply and divide. */ |
| 2498 |
static void |
| 2499 |
cris_init_libfuncs (void) |
| 2500 |
{ |
| 2501 |
set_optab_libfunc (smul_optab, SImode, "__Mul"); |
| 2502 |
set_optab_libfunc (sdiv_optab, SImode, "__Div"); |
| 2503 |
set_optab_libfunc (udiv_optab, SImode, "__Udiv"); |
| 2504 |
set_optab_libfunc (smod_optab, SImode, "__Mod"); |
| 2505 |
set_optab_libfunc (umod_optab, SImode, "__Umod"); |
| 2506 |
|
| 2507 |
/* Atomic data being unaligned is unfortunately a reality. |
| 2508 |
Deal with it. */ |
| 2509 |
if (TARGET_ATOMICS_MAY_CALL_LIBFUNCS) |
| 2510 |
{ |
| 2511 |
set_optab_libfunc (sync_compare_and_swap_optab, SImode, |
| 2512 |
"__cris_atcmpxchgr32"); |
| 2513 |
set_optab_libfunc (sync_compare_and_swap_optab, HImode, |
| 2514 |
"__cris_atcmpxchgr16"); |
| 2515 |
} |
| 2516 |
} |
| 2517 |
|
| 2518 |
/* The INIT_EXPANDERS worker sets the per-function-data initializer and |
| 2519 |
mark functions. */ |
| 2520 |
|
| 2521 |
void |
| 2522 |
cris_init_expanders (void) |
| 2523 |
{ |
| 2524 |
/* Nothing here at the moment. */ |
| 2525 |
} |
| 2526 |
|
| 2527 |
/* Zero initialization is OK for all current fields. */ |
| 2528 |
|
| 2529 |
static struct machine_function * |
| 2530 |
cris_init_machine_status (void) |
| 2531 |
{ |
| 2532 |
return ggc_cleared_alloc<machine_function> (); |
| 2533 |
} |
| 2534 |
|
| 2535 |
/* Split a 2 word move (DI or presumably DF) into component parts. |
| 2536 |
Originally a copy of gen_split_move_double in m32r.cc. */ |
| 2537 |
|
| 2538 |
rtx |
| 2539 |
cris_split_movdx (rtx *operands) |
| 2540 |
{ |
| 2541 |
machine_mode mode = GET_MODE (operands[0]); |
| 2542 |
rtx dest = operands[0]; |
| 2543 |
rtx src = operands[1]; |
| 2544 |
rtx val; |
| 2545 |
|
| 2546 |
/* We used to have to handle (SUBREG (MEM)) here, but that should no |
| 2547 |
longer happen; after reload there are no SUBREGs any more, and we're |
| 2548 |
only called after reload. */ |
| 2549 |
CRIS_ASSERT (GET_CODE (dest) != SUBREG && GET_CODE (src) != SUBREG); |
| 2550 |
|
| 2551 |
start_sequence (); |
| 2552 |
if (REG_P (dest)) |
| 2553 |
{ |
| 2554 |
int dregno = REGNO (dest); |
| 2555 |
|
| 2556 |
/* Reg-to-reg copy. */ |
| 2557 |
if (REG_P (src)) |
| 2558 |
{ |
| 2559 |
int sregno = REGNO (src); |
| 2560 |
|
| 2561 |
int reverse = (dregno == sregno + 1); |
| 2562 |
|
| 2563 |
/* We normally copy the low-numbered register first. However, if |
| 2564 |
the first register operand 0 is the same as the second register of |
| 2565 |
operand 1, we must copy in the opposite order. */ |
| 2566 |
emit_move_insn (operand_subword (dest, reverse, TRUE, mode), |
| 2567 |
operand_subword (src, reverse, TRUE, mode)); |
| 2568 |
|
| 2569 |
emit_move_insn (operand_subword (dest, !reverse, TRUE, mode), |
| 2570 |
operand_subword (src, !reverse, TRUE, mode)); |
| 2571 |
} |
| 2572 |
/* Constant-to-reg copy. */ |
| 2573 |
else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE) |
| 2574 |
{ |
| 2575 |
rtx words[2]; |
| 2576 |
split_double (src, &words[0], &words[1]); |
| 2577 |
emit_move_insn (operand_subword (dest, 0, TRUE, mode), words[0]); |
| 2578 |
|
| 2579 |
emit_move_insn (operand_subword (dest, 1, TRUE, mode), words[1]); |
| 2580 |
} |
| 2581 |
/* Mem-to-reg copy. */ |
| 2582 |
else if (MEM_P (src)) |
| 2583 |
{ |
| 2584 |
/* If the high-address word is used in the address, we must load it |
| 2585 |
last. Otherwise, load it first. */ |
| 2586 |
rtx addr = XEXP (src, 0); |
| 2587 |
int reverse = (refers_to_regno_p (dregno, addr) != 0); |
| 2588 |
|
| 2589 |
/* The original code implies that we can't do |
| 2590 |
move.x [rN+],rM move.x [rN],rM+1 |
| 2591 |
when rN is dead, because of REG_NOTES damage. That is |
| 2592 |
consistent with what I've seen, so don't try it. |
| 2593 |
|
| 2594 |
We have two different cases here; if the addr is POST_INC, |
| 2595 |
just pass it through, otherwise add constants. */ |
| 2596 |
|
| 2597 |
if (GET_CODE (addr) == POST_INC) |
| 2598 |
{ |
| 2599 |
rtx mem; |
| 2600 |
rtx insn; |
| 2601 |
|
| 2602 |
/* Whenever we emit insns with post-incremented |
| 2603 |
addresses ourselves, we must add a post-inc note |
| 2604 |
manually. */ |
| 2605 |
mem = change_address (src, SImode, addr); |
| 2606 |
insn = emit_move_insn (operand_subword (dest, 0, TRUE, mode), |
| 2607 |
mem); |
| 2608 |
if (GET_CODE (XEXP (mem, 0)) == POST_INC) |
| 2609 |
REG_NOTES (insn) |
| 2610 |
= alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0), |
| 2611 |
REG_NOTES (insn)); |
| 2612 |
|
| 2613 |
mem = copy_rtx (mem); |
| 2614 |
insn = emit_move_insn (operand_subword (dest, 1, TRUE, mode), mem); |
| 2615 |
if (GET_CODE (XEXP (mem, 0)) == POST_INC) |
| 2616 |
REG_NOTES (insn) |
| 2617 |
= alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0), |
| 2618 |
REG_NOTES (insn)); |
| 2619 |
} |
| 2620 |
else |
| 2621 |
{ |
| 2622 |
/* Make sure we don't get any other addresses with |
| 2623 |
embedded postincrements. They should be stopped in |
| 2624 |
GO_IF_LEGITIMATE_ADDRESS, but we're here for your |
| 2625 |
safety. */ |
| 2626 |
if (side_effects_p (addr)) |
| 2627 |
fatal_insn ("unexpected side-effects in address", addr); |
| 2628 |
|
| 2629 |
emit_move_insn (operand_subword (dest, reverse, TRUE, mode), |
| 2630 |
change_address |
| 2631 |
(src, SImode, |
| 2632 |
plus_constant (Pmode, addr, |
| 2633 |
reverse * UNITS_PER_WORD))); |
| 2634 |
emit_move_insn (operand_subword (dest, ! reverse, TRUE, mode), |
| 2635 |
change_address |
| 2636 |
(src, SImode, |
| 2637 |
plus_constant (Pmode, addr, |
| 2638 |
(! reverse) * |
| 2639 |
UNITS_PER_WORD))); |
| 2640 |
} |
| 2641 |
} |
| 2642 |
else |
| 2643 |
internal_error ("unknown src"); |
| 2644 |
} |
| 2645 |
/* Reg-to-mem copy or clear mem. */ |
| 2646 |
else if (MEM_P (dest) |
| 2647 |
&& (REG_P (src) |
| 2648 |
|| src == const0_rtx |
| 2649 |
|| src == CONST0_RTX (DFmode))) |
| 2650 |
{ |
| 2651 |
rtx addr = XEXP (dest, 0); |
| 2652 |
|
| 2653 |
if (GET_CODE (addr) == POST_INC) |
| 2654 |
{ |
| 2655 |
rtx mem; |
| 2656 |
rtx insn; |
| 2657 |
|
| 2658 |
/* Whenever we emit insns with post-incremented addresses |
| 2659 |
ourselves, we must add a post-inc note manually. */ |
| 2660 |
mem = change_address (dest, SImode, addr); |
| 2661 |
insn = emit_move_insn (mem, operand_subword (src, 0, TRUE, mode)); |
| 2662 |
if (GET_CODE (XEXP (mem, 0)) == POST_INC) |
| 2663 |
REG_NOTES (insn) |
| 2664 |
= alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0), |
| 2665 |
REG_NOTES (insn)); |
| 2666 |
|
| 2667 |
mem = copy_rtx (mem); |
| 2668 |
insn = emit_move_insn (mem, operand_subword (src, 1, TRUE, mode)); |
| 2669 |
if (GET_CODE (XEXP (mem, 0)) == POST_INC) |
| 2670 |
REG_NOTES (insn) |
| 2671 |
= alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0), |
| 2672 |
REG_NOTES (insn)); |
| 2673 |
} |
| 2674 |
else |
| 2675 |
{ |
| 2676 |
/* Make sure we don't get any other addresses with embedded |
| 2677 |
postincrements. They should be stopped in |
| 2678 |
GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */ |
| 2679 |
if (side_effects_p (addr)) |
| 2680 |
fatal_insn ("unexpected side-effects in address", addr); |
| 2681 |
|
| 2682 |
emit_move_insn (change_address (dest, SImode, addr), |
| 2683 |
operand_subword (src, 0, TRUE, mode)); |
| 2684 |
|
| 2685 |
emit_move_insn (change_address (dest, SImode, |
| 2686 |
plus_constant (Pmode, addr, |
| 2687 |
UNITS_PER_WORD)), |
| 2688 |
operand_subword (src, 1, TRUE, mode)); |
| 2689 |
} |
| 2690 |
} |
| 2691 |
|
| 2692 |
else |
| 2693 |
internal_error ("unknown dest"); |
| 2694 |
|
| 2695 |
val = get_insns (); |
| 2696 |
end_sequence (); |
| 2697 |
return val; |
| 2698 |
} |
| 2699 |
|
| 2700 |
/* Try to split the constant WVAL into a number of separate insns of less cost |
| 2701 |
for the rtx operation CODE and the metric SPEED than using val as-is. |
| 2702 |
Generate those insns if GENERATE. DEST holds the destination, and OP holds |
| 2703 |
the other operand for binary operations; NULL when CODE is SET. Return the |
| 2704 |
number of insns for the operation or 0 if the constant can't be usefully |
| 2705 |
split (because it's already minimal or is not within range for the known |
| 2706 |
methods). Parts stolen from arm.cc. */ |
| 2707 |
|
| 2708 |
int |
| 2709 |
cris_split_constant (HOST_WIDE_INT wval, enum rtx_code code, |
| 2710 |
machine_mode mode, bool speed ATTRIBUTE_UNUSED, |
| 2711 |
bool generate, rtx dest, rtx op) |
| 2712 |
{ |
| 2713 |
int32_t ival = (int32_t) wval; |
| 2714 |
uint32_t uval = (uint32_t) wval; |
| 2715 |
|
| 2716 |
/* Can we do with two addq or two subq, improving chances of filling a |
| 2717 |
delay-slot? At worst, we break even, both performance and |
| 2718 |
size-wise. */ |
| 2719 |
if (code == PLUS |
| 2720 |
&& (IN_RANGE (ival, -63 * 2, -63 - 1) |
| 2721 |
|| IN_RANGE (ival, 63 + 1, 63 * 2))) |
| 2722 |
{ |
| 2723 |
if (generate) |
| 2724 |
{ |
| 2725 |
int sign = ival < 0 ? -1 : 1; |
| 2726 |
int aval = abs (ival); |
| 2727 |
|
| 2728 |
if (mode != SImode) |
| 2729 |
{ |
| 2730 |
dest = gen_rtx_REG (SImode, REGNO (dest)); |
| 2731 |
op = gen_rtx_REG (SImode, REGNO (op)); |
| 2732 |
} |
| 2733 |
emit_insn (gen_addsi3 (dest, op, GEN_INT (63 * sign))); |
| 2734 |
emit_insn (gen_addsi3 (dest, op, GEN_INT ((aval - 63) * sign))); |
| 2735 |
} |
| 2736 |
return 2; |
| 2737 |
} |
| 2738 |
|
| 2739 |
if (code != AND || IN_RANGE (ival, -32, 31) |
| 2740 |
/* Implemented using movu.[bw] elsewhere. */ |
| 2741 |
|| ival == 255 || ival == 65535 |
| 2742 |
/* Implemented using clear.[bw] elsewhere. */ |
| 2743 |
|| uval == 0xffffff00 || uval == 0xffff0000) |
| 2744 |
return 0; |
| 2745 |
|
| 2746 |
int i; |
| 2747 |
|
| 2748 |
int msb_zeros = 0; |
| 2749 |
int lsb_zeros = 0; |
| 2750 |
|
| 2751 |
/* Count number of leading zeros. */ |
| 2752 |
for (i = 31; i >= 0; i--) |
| 2753 |
{ |
| 2754 |
if ((uval & (1 << i)) == 0) |
| 2755 |
msb_zeros++; |
| 2756 |
else |
| 2757 |
break; |
| 2758 |
} |
| 2759 |
|
| 2760 |
/* Count number of trailing zero's. */ |
| 2761 |
for (i = 0; i <= 31; i++) |
| 2762 |
{ |
| 2763 |
if ((uval & (1 << i)) == 0) |
| 2764 |
lsb_zeros++; |
| 2765 |
else |
| 2766 |
break; |
| 2767 |
} |
| 2768 |
|
| 2769 |
/* Is there a lowest or highest part that is zero (but not both) |
| 2770 |
and the non-zero part is just ones? */ |
| 2771 |
if (exact_log2 ((uval >> lsb_zeros) + 1) > 0 |
| 2772 |
&& (lsb_zeros != 0) != (msb_zeros != 0)) |
| 2773 |
{ |
| 2774 |
/* If so, we can shift OP in the zero direction, then back. We don't |
| 2775 |
nominally win anything for uval < 256, except that the insns are split |
| 2776 |
into slottable insns so it's always beneficial. */ |
| 2777 |
if (generate) |
| 2778 |
{ |
| 2779 |
if (mode != SImode) |
| 2780 |
{ |
| 2781 |
dest = gen_rtx_REG (SImode, REGNO (dest)); |
| 2782 |
op = gen_rtx_REG (SImode, REGNO (op)); |
| 2783 |
} |
| 2784 |
if (msb_zeros) |
| 2785 |
{ |
| 2786 |
emit_insn (gen_ashlsi3 (dest, op, GEN_INT (msb_zeros))); |
| 2787 |
emit_insn (gen_lshrsi3 (dest, op, GEN_INT (msb_zeros))); |
| 2788 |
} |
| 2789 |
else |
| 2790 |
{ |
| 2791 |
emit_insn (gen_lshrsi3 (dest, op, GEN_INT (lsb_zeros))); |
| 2792 |
emit_insn (gen_ashlsi3 (dest, op, GEN_INT (lsb_zeros))); |
| 2793 |
} |
| 2794 |
} |
| 2795 |
return 2; |
| 2796 |
} |
| 2797 |
|
| 2798 |
return 0; |
| 2799 |
} |
| 2800 |
|
| 2801 |
/* Try to change a comparison against a constant to be against zero, and |
| 2802 |
an unsigned compare against zero to be an equality test. Beware: |
| 2803 |
only valid for compares of integer-type operands. Also, note that we |
| 2804 |
don't use operand 0 at the moment. */ |
| 2805 |
|
| 2806 |
void |
| 2807 |
cris_reduce_compare (rtx *relp, rtx *, rtx *op1p) |
| 2808 |
{ |
| 2809 |
rtx op1 = *op1p; |
| 2810 |
rtx_code code = GET_CODE (*relp); |
| 2811 |
|
| 2812 |
/* Code lifted mostly from emit_store_flag_1. */ |
| 2813 |
switch (code) |
| 2814 |
{ |
| 2815 |
case LT: |
| 2816 |
if (op1 == const1_rtx) |
| 2817 |
code = LE; |
| 2818 |
break; |
| 2819 |
case LE: |
| 2820 |
if (op1 == constm1_rtx) |
| 2821 |
code = LT; |
| 2822 |
break; |
| 2823 |
case GE: |
| 2824 |
if (op1 == const1_rtx) |
| 2825 |
code = GT; |
| 2826 |
break; |
| 2827 |
case GT: |
| 2828 |
if (op1 == constm1_rtx) |
| 2829 |
code = GE; |
| 2830 |
break; |
| 2831 |
case GEU: |
| 2832 |
if (op1 == const1_rtx) |
| 2833 |
code = NE; |
| 2834 |
break; |
| 2835 |
case LTU: |
| 2836 |
if (op1 == const1_rtx) |
| 2837 |
code = EQ; |
| 2838 |
break; |
| 2839 |
case GTU: |
| 2840 |
if (op1 == const0_rtx) |
| 2841 |
code = NE; |
| 2842 |
break; |
| 2843 |
case LEU: |
| 2844 |
if (op1 == const0_rtx) |
| 2845 |
code = EQ; |
| 2846 |
break; |
| 2847 |
default: |
| 2848 |
break; |
| 2849 |
} |
| 2850 |
|
| 2851 |
if (code != GET_CODE (*relp)) |
| 2852 |
{ |
| 2853 |
*op1p = const0_rtx; |
| 2854 |
PUT_CODE (*relp, code); |
| 2855 |
} |
| 2856 |
} |
| 2857 |
|
| 2858 |
/* The expander for the prologue pattern name. */ |
| 2859 |
|
| 2860 |
void |
| 2861 |
cris_expand_prologue (void) |
| 2862 |
{ |
| 2863 |
int regno; |
| 2864 |
int size = get_frame_size (); |
| 2865 |
/* Shorten the used name for readability. */ |
| 2866 |
int cfoa_size = crtl->outgoing_args_size; |
| 2867 |
int last_movem_reg = -1; |
| 2868 |
int framesize = 0; |
| 2869 |
rtx mem, insn; |
| 2870 |
int return_address_on_stack = cris_return_address_on_stack (); |
| 2871 |
int n_movem_regs = 0; |
| 2872 |
int pretend = crtl->args.pretend_args_size; |
| 2873 |
|
| 2874 |
/* Don't do anything if no prologues or epilogues are wanted. */ |
| 2875 |
if (!TARGET_PROLOGUE_EPILOGUE) |
| 2876 |
return; |
| 2877 |
|
| 2878 |
CRIS_ASSERT (size >= 0); |
| 2879 |
|
| 2880 |
/* Align the size to what's best for the CPU model. */ |
| 2881 |
if (TARGET_STACK_ALIGN) |
| 2882 |
size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1; |
| 2883 |
|
| 2884 |
if (pretend) |
| 2885 |
{ |
| 2886 |
/* See also cris_setup_incoming_varargs where |
| 2887 |
cfun->machine->stdarg_regs is set. There are other setters of |
| 2888 |
crtl->args.pretend_args_size than stdarg handling, like |
| 2889 |
for an argument passed with parts in R13 and stack. We must |
| 2890 |
not store R13 into the pretend-area for that case, as GCC does |
| 2891 |
that itself. "Our" store would be marked as redundant and GCC |
| 2892 |
will attempt to remove it, which will then be flagged as an |
| 2893 |
internal error; trying to remove a frame-related insn. */ |
| 2894 |
int stdarg_regs = cfun->machine->stdarg_regs; |
| 2895 |
|
| 2896 |
framesize += pretend; |
| 2897 |
|
| 2898 |
for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1; |
| 2899 |
stdarg_regs > 0; |
| 2900 |
regno--, pretend -= 4, stdarg_regs--) |
| 2901 |
{ |
| 2902 |
insn = emit_insn (gen_add2_insn (stack_pointer_rtx, GEN_INT (-4))); |
| 2903 |
/* FIXME: When dwarf2 frame output and unless asynchronous |
| 2904 |
exceptions, make dwarf2 bundle together all stack |
| 2905 |
adjustments like it does for registers between stack |
| 2906 |
adjustments. */ |
| 2907 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 2908 |
|
| 2909 |
mem = gen_rtx_MEM (SImode, stack_pointer_rtx); |
| 2910 |
set_mem_alias_set (mem, get_varargs_alias_set ()); |
| 2911 |
insn = emit_move_insn (mem, gen_raw_REG (SImode, regno)); |
| 2912 |
|
| 2913 |
/* Note the absence of RTX_FRAME_RELATED_P on the above insn: |
| 2914 |
the value isn't restored, so we don't want to tell dwarf2 |
| 2915 |
that it's been stored to stack, else EH handling info would |
| 2916 |
get confused. */ |
| 2917 |
} |
| 2918 |
|
| 2919 |
/* For other setters of crtl->args.pretend_args_size, we |
| 2920 |
just adjust the stack by leaving the remaining size in |
| 2921 |
"pretend", handled below. */ |
| 2922 |
} |
| 2923 |
|
| 2924 |
/* Save SRP if not a leaf function. */ |
| 2925 |
if (return_address_on_stack) |
| 2926 |
{ |
| 2927 |
insn = emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 2928 |
GEN_INT (-4 - pretend))); |
| 2929 |
pretend = 0; |
| 2930 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 2931 |
|
| 2932 |
mem = gen_rtx_MEM (SImode, stack_pointer_rtx); |
| 2933 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 2934 |
insn = emit_move_insn (mem, gen_raw_REG (SImode, CRIS_SRP_REGNUM)); |
| 2935 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 2936 |
framesize += 4; |
| 2937 |
} |
| 2938 |
|
| 2939 |
/* Set up the frame pointer, if needed. */ |
| 2940 |
if (frame_pointer_needed) |
| 2941 |
{ |
| 2942 |
insn = emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 2943 |
GEN_INT (-4 - pretend))); |
| 2944 |
pretend = 0; |
| 2945 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 2946 |
|
| 2947 |
mem = gen_rtx_MEM (SImode, stack_pointer_rtx); |
| 2948 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 2949 |
insn = emit_move_insn (mem, hard_frame_pointer_rtx); |
| 2950 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 2951 |
|
| 2952 |
insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx); |
| 2953 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 2954 |
|
| 2955 |
framesize += 4; |
| 2956 |
} |
| 2957 |
|
| 2958 |
/* Between frame-pointer and saved registers lie the area for local |
| 2959 |
variables. If we get here with "pretended" size remaining, count |
| 2960 |
it into the general stack size. */ |
| 2961 |
size += pretend; |
| 2962 |
|
| 2963 |
/* Get a contiguous sequence of registers, starting with R0, that need |
| 2964 |
to be saved. */ |
| 2965 |
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) |
| 2966 |
{ |
| 2967 |
if (cris_reg_saved_in_regsave_area (regno)) |
| 2968 |
{ |
| 2969 |
n_movem_regs++; |
| 2970 |
|
| 2971 |
/* Check if movem may be used for registers so far. */ |
| 2972 |
if (regno == last_movem_reg + 1) |
| 2973 |
/* Yes, update next expected register. */ |
| 2974 |
last_movem_reg = regno; |
| 2975 |
else |
| 2976 |
{ |
| 2977 |
/* We cannot use movem for all registers. We have to flush |
| 2978 |
any movem:ed registers we got so far. */ |
| 2979 |
if (last_movem_reg != -1) |
| 2980 |
{ |
| 2981 |
int n_saved |
| 2982 |
= (n_movem_regs == 1) ? 1 : last_movem_reg + 1; |
| 2983 |
|
| 2984 |
/* It is a win to use a side-effect assignment for |
| 2985 |
64 <= size <= 128. But side-effect on movem was |
| 2986 |
not usable for CRIS v0..3. Also only do it if |
| 2987 |
side-effects insns are allowed. */ |
| 2988 |
if ((last_movem_reg + 1) * 4 + size >= 64 |
| 2989 |
&& (last_movem_reg + 1) * 4 + size <= 128 |
| 2990 |
&& cris_cpu_version >= CRIS_CPU_SVINTO |
| 2991 |
/* Don't use side-effect assignment for a single |
| 2992 |
move. */ |
| 2993 |
&& n_saved > 1 |
| 2994 |
&& TARGET_SIDE_EFFECT_PREFIXES) |
| 2995 |
{ |
| 2996 |
mem |
| 2997 |
= gen_rtx_MEM (SImode, |
| 2998 |
plus_constant (Pmode, stack_pointer_rtx, |
| 2999 |
-(n_saved * 4 + size))); |
| 3000 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3001 |
insn |
| 3002 |
= cris_emit_movem_store (mem, GEN_INT (n_saved), |
| 3003 |
-(n_saved * 4 + size), |
| 3004 |
true); |
| 3005 |
} |
| 3006 |
else |
| 3007 |
{ |
| 3008 |
insn |
| 3009 |
= emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 3010 |
GEN_INT (-(n_saved * 4 |
| 3011 |
+ size)))); |
| 3012 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 3013 |
|
| 3014 |
mem = gen_rtx_MEM (SImode, stack_pointer_rtx); |
| 3015 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3016 |
insn = cris_emit_movem_store (mem, GEN_INT (n_saved), |
| 3017 |
0, true); |
| 3018 |
} |
| 3019 |
|
| 3020 |
framesize += n_saved * 4 + size; |
| 3021 |
last_movem_reg = -1; |
| 3022 |
size = 0; |
| 3023 |
} |
| 3024 |
|
| 3025 |
insn = emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 3026 |
GEN_INT (-4 - size))); |
| 3027 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 3028 |
|
| 3029 |
mem = gen_rtx_MEM (SImode, stack_pointer_rtx); |
| 3030 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3031 |
insn = emit_move_insn (mem, gen_raw_REG (SImode, regno)); |
| 3032 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 3033 |
|
| 3034 |
framesize += 4 + size; |
| 3035 |
size = 0; |
| 3036 |
} |
| 3037 |
} |
| 3038 |
} |
| 3039 |
|
| 3040 |
/* Check after, if we could movem all registers. This is the normal case. */ |
| 3041 |
if (last_movem_reg != -1) |
| 3042 |
{ |
| 3043 |
int n_saved |
| 3044 |
= (n_movem_regs == 1) ? 1 : last_movem_reg + 1; |
| 3045 |
|
| 3046 |
/* Side-effect on movem was not usable for CRIS v0..3. Also only |
| 3047 |
do it if side-effects insns are allowed. */ |
| 3048 |
if ((last_movem_reg + 1) * 4 + size >= 64 |
| 3049 |
&& (last_movem_reg + 1) * 4 + size <= 128 |
| 3050 |
&& cris_cpu_version >= CRIS_CPU_SVINTO |
| 3051 |
/* Don't use side-effect assignment for a single move. */ |
| 3052 |
&& n_saved > 1 |
| 3053 |
&& TARGET_SIDE_EFFECT_PREFIXES) |
| 3054 |
{ |
| 3055 |
mem |
| 3056 |
= gen_rtx_MEM (SImode, |
| 3057 |
plus_constant (Pmode, stack_pointer_rtx, |
| 3058 |
-(n_saved * 4 + size))); |
| 3059 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3060 |
insn = cris_emit_movem_store (mem, GEN_INT (n_saved), |
| 3061 |
-(n_saved * 4 + size), true); |
| 3062 |
} |
| 3063 |
else |
| 3064 |
{ |
| 3065 |
insn = emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 3066 |
GEN_INT (-(n_saved * 4 + size)))); |
| 3067 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 3068 |
|
| 3069 |
mem = gen_rtx_MEM (SImode, stack_pointer_rtx); |
| 3070 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3071 |
insn = cris_emit_movem_store (mem, GEN_INT (n_saved), 0, true); |
| 3072 |
} |
| 3073 |
|
| 3074 |
framesize += n_saved * 4 + size; |
| 3075 |
/* We have to put outgoing argument space after regs. */ |
| 3076 |
if (cfoa_size) |
| 3077 |
{ |
| 3078 |
insn = emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 3079 |
GEN_INT (-cfoa_size))); |
| 3080 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 3081 |
framesize += cfoa_size; |
| 3082 |
} |
| 3083 |
} |
| 3084 |
else if ((size + cfoa_size) > 0) |
| 3085 |
{ |
| 3086 |
insn = emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 3087 |
GEN_INT (-(cfoa_size + size)))); |
| 3088 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 3089 |
framesize += size + cfoa_size; |
| 3090 |
} |
| 3091 |
|
| 3092 |
/* FIXME: -mmax-stackframe=SIZE is obsoleted; use -Wstack-usage=SIZE |
| 3093 |
instead. Make it an alias? */ |
| 3094 |
if (cris_max_stackframe && framesize > cris_max_stackframe) |
| 3095 |
warning (0, "stackframe too big: %d bytes", framesize); |
| 3096 |
|
| 3097 |
if (flag_stack_usage_info) |
| 3098 |
current_function_static_stack_size = framesize; |
| 3099 |
} |
| 3100 |
|
| 3101 |
/* The expander for the epilogue pattern. */ |
| 3102 |
|
| 3103 |
void |
| 3104 |
cris_expand_epilogue (void) |
| 3105 |
{ |
| 3106 |
int regno; |
| 3107 |
int size = get_frame_size (); |
| 3108 |
int last_movem_reg = -1; |
| 3109 |
int argspace_offset = crtl->outgoing_args_size; |
| 3110 |
int pretend = crtl->args.pretend_args_size; |
| 3111 |
rtx mem; |
| 3112 |
bool return_address_on_stack = cris_return_address_on_stack (); |
| 3113 |
/* A reference may have been optimized out |
| 3114 |
(like the abort () in fde_split in unwind-dw2-fde.c, at least 3.2.1) |
| 3115 |
so check that it's still used. */ |
| 3116 |
int n_movem_regs = 0; |
| 3117 |
|
| 3118 |
if (!TARGET_PROLOGUE_EPILOGUE) |
| 3119 |
return; |
| 3120 |
|
| 3121 |
/* Align byte count of stack frame. */ |
| 3122 |
if (TARGET_STACK_ALIGN) |
| 3123 |
size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1; |
| 3124 |
|
| 3125 |
/* Check how many saved regs we can movem. They start at r0 and must |
| 3126 |
be contiguous. */ |
| 3127 |
for (regno = 0; |
| 3128 |
regno < FIRST_PSEUDO_REGISTER; |
| 3129 |
regno++) |
| 3130 |
if (cris_reg_saved_in_regsave_area (regno)) |
| 3131 |
{ |
| 3132 |
n_movem_regs++; |
| 3133 |
|
| 3134 |
if (regno == last_movem_reg + 1) |
| 3135 |
last_movem_reg = regno; |
| 3136 |
else |
| 3137 |
break; |
| 3138 |
} |
| 3139 |
|
| 3140 |
/* If there was only one register that really needed to be saved |
| 3141 |
through movem, don't use movem. */ |
| 3142 |
if (n_movem_regs == 1) |
| 3143 |
last_movem_reg = -1; |
| 3144 |
|
| 3145 |
/* Now emit "normal" move insns for all regs higher than the movem |
| 3146 |
regs. */ |
| 3147 |
for (regno = FIRST_PSEUDO_REGISTER - 1; |
| 3148 |
regno > last_movem_reg; |
| 3149 |
regno--) |
| 3150 |
if (cris_reg_saved_in_regsave_area (regno)) |
| 3151 |
{ |
| 3152 |
rtx insn; |
| 3153 |
|
| 3154 |
if (argspace_offset) |
| 3155 |
{ |
| 3156 |
/* There is an area for outgoing parameters located before |
| 3157 |
the saved registers. We have to adjust for that. */ |
| 3158 |
emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 3159 |
GEN_INT (argspace_offset))); |
| 3160 |
/* Make sure we only do this once. */ |
| 3161 |
argspace_offset = 0; |
| 3162 |
} |
| 3163 |
|
| 3164 |
mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode, |
| 3165 |
stack_pointer_rtx)); |
| 3166 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3167 |
insn = emit_move_insn (gen_raw_REG (SImode, regno), mem); |
| 3168 |
|
| 3169 |
/* Whenever we emit insns with post-incremented addresses |
| 3170 |
ourselves, we must add a post-inc note manually. */ |
| 3171 |
REG_NOTES (insn) |
| 3172 |
= alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn)); |
| 3173 |
} |
| 3174 |
|
| 3175 |
/* If we have any movem-restore, do it now. */ |
| 3176 |
if (last_movem_reg != -1) |
| 3177 |
{ |
| 3178 |
rtx insn; |
| 3179 |
|
| 3180 |
if (argspace_offset) |
| 3181 |
{ |
| 3182 |
emit_insn (gen_add2_insn (stack_pointer_rtx, GEN_INT (argspace_offset))); |
| 3183 |
argspace_offset = 0; |
| 3184 |
} |
| 3185 |
|
| 3186 |
mem = gen_rtx_MEM (SImode, |
| 3187 |
gen_rtx_POST_INC (SImode, stack_pointer_rtx)); |
| 3188 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3189 |
insn |
| 3190 |
= emit_insn (cris_gen_movem_load (mem, GEN_INT (last_movem_reg + 1))); |
| 3191 |
/* Whenever we emit insns with post-incremented addresses |
| 3192 |
ourselves, we must add a post-inc note manually. */ |
| 3193 |
if (side_effects_p (PATTERN (insn))) |
| 3194 |
REG_NOTES (insn) |
| 3195 |
= alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn)); |
| 3196 |
} |
| 3197 |
|
| 3198 |
/* If we don't clobber all of the allocated stack area (we've already |
| 3199 |
deallocated saved registers), GCC might want to schedule loads from |
| 3200 |
the stack to *after* the stack-pointer restore, which introduces an |
| 3201 |
interrupt race condition. This happened for the initial-value |
| 3202 |
SRP-restore for g++.dg/eh/registers1.C (noticed by inspection of |
| 3203 |
other failure for that test). It also happened for the stack slot |
| 3204 |
for the return value in (one version of) |
| 3205 |
linux/fs/dcache.c:__d_lookup, at least with "-O2 |
| 3206 |
-fno-omit-frame-pointer". */ |
| 3207 |
|
| 3208 |
/* Restore frame pointer if necessary. */ |
| 3209 |
if (frame_pointer_needed) |
| 3210 |
{ |
| 3211 |
rtx insn; |
| 3212 |
|
| 3213 |
emit_insn (gen_cris_frame_deallocated_barrier ()); |
| 3214 |
|
| 3215 |
emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx); |
| 3216 |
mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode, |
| 3217 |
stack_pointer_rtx)); |
| 3218 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3219 |
insn = emit_move_insn (hard_frame_pointer_rtx, mem); |
| 3220 |
|
| 3221 |
/* Whenever we emit insns with post-incremented addresses |
| 3222 |
ourselves, we must add a post-inc note manually. */ |
| 3223 |
REG_NOTES (insn) |
| 3224 |
= alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn)); |
| 3225 |
} |
| 3226 |
else if ((size + argspace_offset) != 0) |
| 3227 |
{ |
| 3228 |
emit_insn (gen_cris_frame_deallocated_barrier ()); |
| 3229 |
|
| 3230 |
/* If there was no frame-pointer to restore sp from, we must |
| 3231 |
explicitly deallocate local variables. */ |
| 3232 |
|
| 3233 |
/* Handle space for outgoing parameters that hasn't been handled |
| 3234 |
yet. */ |
| 3235 |
size += argspace_offset; |
| 3236 |
|
| 3237 |
emit_insn (gen_add2_insn (stack_pointer_rtx, GEN_INT (size))); |
| 3238 |
} |
| 3239 |
|
| 3240 |
/* If this function has no pushed register parameters |
| 3241 |
(stdargs/varargs), and if it is not a leaf function, then we have |
| 3242 |
the return address on the stack. */ |
| 3243 |
if (return_address_on_stack && pretend == 0) |
| 3244 |
{ |
| 3245 |
if (crtl->calls_eh_return) |
| 3246 |
{ |
| 3247 |
rtx mem; |
| 3248 |
rtx insn; |
| 3249 |
rtx srpreg = gen_raw_REG (SImode, CRIS_SRP_REGNUM); |
| 3250 |
mem = gen_rtx_MEM (SImode, |
| 3251 |
gen_rtx_POST_INC (SImode, |
| 3252 |
stack_pointer_rtx)); |
| 3253 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3254 |
insn = emit_move_insn (srpreg, mem); |
| 3255 |
|
| 3256 |
/* Whenever we emit insns with post-incremented addresses |
| 3257 |
ourselves, we must add a post-inc note manually. */ |
| 3258 |
REG_NOTES (insn) |
| 3259 |
= alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn)); |
| 3260 |
|
| 3261 |
if (crtl->calls_eh_return) |
| 3262 |
emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 3263 |
gen_raw_REG (SImode, CRIS_STACKADJ_REG))); |
| 3264 |
cris_expand_return (false); |
| 3265 |
} |
| 3266 |
else |
| 3267 |
cris_expand_return (true); |
| 3268 |
|
| 3269 |
return; |
| 3270 |
} |
| 3271 |
|
| 3272 |
/* If we pushed some register parameters, then adjust the stack for |
| 3273 |
them. */ |
| 3274 |
if (pretend != 0) |
| 3275 |
{ |
| 3276 |
/* If SRP is stored on the way, we need to restore it first. */ |
| 3277 |
if (return_address_on_stack) |
| 3278 |
{ |
| 3279 |
rtx mem; |
| 3280 |
rtx srpreg = gen_raw_REG (SImode, CRIS_SRP_REGNUM); |
| 3281 |
rtx insn; |
| 3282 |
|
| 3283 |
mem = gen_rtx_MEM (SImode, |
| 3284 |
gen_rtx_POST_INC (SImode, |
| 3285 |
stack_pointer_rtx)); |
| 3286 |
set_mem_alias_set (mem, get_frame_alias_set ()); |
| 3287 |
insn = emit_move_insn (srpreg, mem); |
| 3288 |
|
| 3289 |
/* Whenever we emit insns with post-incremented addresses |
| 3290 |
ourselves, we must add a post-inc note manually. */ |
| 3291 |
REG_NOTES (insn) |
| 3292 |
= alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn)); |
| 3293 |
} |
| 3294 |
|
| 3295 |
emit_insn (gen_add2_insn (stack_pointer_rtx, GEN_INT (pretend))); |
| 3296 |
} |
| 3297 |
|
| 3298 |
/* Perform the "physical" unwinding that the EH machinery calculated. */ |
| 3299 |
if (crtl->calls_eh_return) |
| 3300 |
emit_insn (gen_add2_insn (stack_pointer_rtx, |
| 3301 |
gen_raw_REG (SImode, CRIS_STACKADJ_REG))); |
| 3302 |
cris_expand_return (false); |
| 3303 |
} |
| 3304 |
|
| 3305 |
/* Worker function for generating movem from mem for load_multiple. */ |
| 3306 |
|
| 3307 |
rtx |
| 3308 |
cris_gen_movem_load (rtx src, rtx nregs_rtx) |
| 3309 |
{ |
| 3310 |
int nregs = INTVAL (nregs_rtx); |
| 3311 |
rtvec vec; |
| 3312 |
int eltno = 1; |
| 3313 |
int i; |
| 3314 |
rtx srcreg = XEXP (src, 0); |
| 3315 |
unsigned int regno = nregs - 1; |
| 3316 |
int regno_inc = -1; |
| 3317 |
|
| 3318 |
if (GET_CODE (srcreg) == POST_INC) |
| 3319 |
srcreg = XEXP (srcreg, 0); |
| 3320 |
|
| 3321 |
CRIS_ASSERT (REG_P (srcreg)); |
| 3322 |
|
| 3323 |
/* Don't use movem for just one insn. The insns are equivalent. */ |
| 3324 |
if (nregs == 1) |
| 3325 |
return gen_movsi (gen_rtx_REG (SImode, 0), src); |
| 3326 |
|
| 3327 |
vec = rtvec_alloc (nregs + (GET_CODE (XEXP (src, 0)) == POST_INC)); |
| 3328 |
|
| 3329 |
if (GET_CODE (XEXP (src, 0)) == POST_INC) |
| 3330 |
{ |
| 3331 |
RTVEC_ELT (vec, 1) |
| 3332 |
= gen_rtx_SET (srcreg, plus_constant (Pmode, srcreg, nregs * 4)); |
| 3333 |
eltno++; |
| 3334 |
} |
| 3335 |
|
| 3336 |
src = replace_equiv_address (src, srcreg); |
| 3337 |
RTVEC_ELT (vec, 0) |
| 3338 |
= gen_rtx_SET (gen_rtx_REG (SImode, regno), src); |
| 3339 |
regno += regno_inc; |
| 3340 |
|
| 3341 |
for (i = 1; i < nregs; i++, eltno++) |
| 3342 |
{ |
| 3343 |
RTVEC_ELT (vec, eltno) |
| 3344 |
= gen_rtx_SET (gen_rtx_REG (SImode, regno), |
| 3345 |
adjust_address_nv (src, SImode, i * 4)); |
| 3346 |
regno += regno_inc; |
| 3347 |
} |
| 3348 |
|
| 3349 |
return gen_rtx_PARALLEL (VOIDmode, vec); |
| 3350 |
} |
| 3351 |
|
| 3352 |
/* Convenience function for CRIS-local use of emit_insn, wrapping the |
| 3353 |
argument in a parallel with a clobber of CRIS_CC0_REGNUM before |
| 3354 |
passing on to emit_insn. */ |
| 3355 |
|
| 3356 |
rtx_insn * |
| 3357 |
cris_emit_insn (rtx x) |
| 3358 |
{ |
| 3359 |
rtvec vec = rtvec_alloc (2); |
| 3360 |
|
| 3361 |
RTVEC_ELT (vec, 0) = x; |
| 3362 |
RTVEC_ELT (vec, 1) |
| 3363 |
= gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, CRIS_CC0_REGNUM)); |
| 3364 |
|
| 3365 |
return emit_insn (gen_rtx_PARALLEL (VOIDmode, vec)); |
| 3366 |
} |
| 3367 |
|
| 3368 |
/* Worker function for generating movem to mem. If FRAME_RELATED, notes |
| 3369 |
are added that the dwarf2 machinery understands. */ |
| 3370 |
|
| 3371 |
rtx |
| 3372 |
cris_emit_movem_store (rtx dest, rtx nregs_rtx, int increment, |
| 3373 |
bool frame_related) |
| 3374 |
{ |
| 3375 |
int nregs = INTVAL (nregs_rtx); |
| 3376 |
rtvec vec; |
| 3377 |
int eltno = 1; |
| 3378 |
int i; |
| 3379 |
rtx insn; |
| 3380 |
rtx destreg = XEXP (dest, 0); |
| 3381 |
unsigned int regno = nregs - 1; |
| 3382 |
int regno_inc = -1; |
| 3383 |
|
| 3384 |
if (GET_CODE (destreg) == POST_INC) |
| 3385 |
increment += nregs * 4; |
| 3386 |
|
| 3387 |
if (GET_CODE (destreg) == POST_INC || GET_CODE (destreg) == PLUS) |
| 3388 |
destreg = XEXP (destreg, 0); |
| 3389 |
|
| 3390 |
CRIS_ASSERT (REG_P (destreg)); |
| 3391 |
|
| 3392 |
/* Don't use movem for just one insn. The insns are equivalent. */ |
| 3393 |
if (nregs == 1) |
| 3394 |
{ |
| 3395 |
if (increment == 0) |
| 3396 |
{ |
| 3397 |
insn = emit_move_insn (dest, gen_rtx_REG (SImode, 0)); |
| 3398 |
if (frame_related) |
| 3399 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 3400 |
return insn; |
| 3401 |
} |
| 3402 |
|
| 3403 |
/* If there was a request for a side-effect, create the ordinary |
| 3404 |
parallel. */ |
| 3405 |
vec = rtvec_alloc (3); |
| 3406 |
|
| 3407 |
rtx mov = gen_rtx_SET (dest, gen_rtx_REG (SImode, 0)); |
| 3408 |
RTVEC_ELT (vec, 0) = mov; |
| 3409 |
RTVEC_ELT (vec, 1) = gen_rtx_SET (destreg, plus_constant (Pmode, destreg, |
| 3410 |
increment)); |
| 3411 |
RTVEC_ELT (vec, 2) |
| 3412 |
= gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, CRIS_CC0_REGNUM)); |
| 3413 |
|
| 3414 |
if (frame_related) |
| 3415 |
{ |
| 3416 |
RTX_FRAME_RELATED_P (mov) = 1; |
| 3417 |
RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1; |
| 3418 |
} |
| 3419 |
} |
| 3420 |
else |
| 3421 |
{ |
| 3422 |
vec = rtvec_alloc (nregs + (increment != 0 ? 1 : 0)); |
| 3423 |
RTVEC_ELT (vec, 0) |
| 3424 |
= gen_rtx_SET (replace_equiv_address (dest, |
| 3425 |
plus_constant (Pmode, destreg, |
| 3426 |
increment)), |
| 3427 |
gen_rtx_REG (SImode, regno)); |
| 3428 |
regno += regno_inc; |
| 3429 |
|
| 3430 |
/* The dwarf2 info wants this mark on each component in a parallel |
| 3431 |
that's part of the prologue (though it's optional on the first |
| 3432 |
component). */ |
| 3433 |
if (frame_related) |
| 3434 |
RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 0)) = 1; |
| 3435 |
|
| 3436 |
if (increment != 0) |
| 3437 |
{ |
| 3438 |
RTVEC_ELT (vec, 1) |
| 3439 |
= gen_rtx_SET (destreg, plus_constant (Pmode, destreg, |
| 3440 |
increment != 0 |
| 3441 |
? increment : nregs * 4)); |
| 3442 |
eltno++; |
| 3443 |
|
| 3444 |
if (frame_related) |
| 3445 |
RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1; |
| 3446 |
|
| 3447 |
/* Don't call adjust_address_nv on a post-incremented address if |
| 3448 |
we can help it. */ |
| 3449 |
if (GET_CODE (XEXP (dest, 0)) == POST_INC) |
| 3450 |
dest = replace_equiv_address (dest, destreg); |
| 3451 |
} |
| 3452 |
|
| 3453 |
for (i = 1; i < nregs; i++, eltno++) |
| 3454 |
{ |
| 3455 |
RTVEC_ELT (vec, eltno) |
| 3456 |
= gen_rtx_SET (adjust_address_nv (dest, SImode, i * 4), |
| 3457 |
gen_rtx_REG (SImode, regno)); |
| 3458 |
if (frame_related) |
| 3459 |
RTX_FRAME_RELATED_P (RTVEC_ELT (vec, eltno)) = 1; |
| 3460 |
regno += regno_inc; |
| 3461 |
} |
| 3462 |
} |
| 3463 |
|
| 3464 |
insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, vec)); |
| 3465 |
|
| 3466 |
/* Because dwarf2out.cc handles the insns in a parallel as a sequence, |
| 3467 |
we need to keep the stack adjustment separate, after the |
| 3468 |
MEM-setters. Else the stack-adjustment in the second component of |
| 3469 |
the parallel would be mishandled; the offsets for the SETs that |
| 3470 |
follow it would be wrong. We prepare for this by adding a |
| 3471 |
REG_FRAME_RELATED_EXPR with the MEM-setting parts in a SEQUENCE |
| 3472 |
followed by the increment. Note that we have FRAME_RELATED_P on |
| 3473 |
all the SETs, including the original stack adjustment SET in the |
| 3474 |
parallel. */ |
| 3475 |
if (frame_related) |
| 3476 |
{ |
| 3477 |
if (increment != 0) |
| 3478 |
{ |
| 3479 |
rtx seq = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nregs + 1)); |
| 3480 |
XVECEXP (seq, 0, 0) = copy_rtx (XVECEXP (PATTERN (insn), 0, 0)); |
| 3481 |
for (i = 1; i < nregs; i++) |
| 3482 |
XVECEXP (seq, 0, i) |
| 3483 |
= copy_rtx (XVECEXP (PATTERN (insn), 0, i + 1)); |
| 3484 |
XVECEXP (seq, 0, nregs) = copy_rtx (XVECEXP (PATTERN (insn), 0, 1)); |
| 3485 |
add_reg_note (insn, REG_FRAME_RELATED_EXPR, seq); |
| 3486 |
} |
| 3487 |
|
| 3488 |
RTX_FRAME_RELATED_P (insn) = 1; |
| 3489 |
} |
| 3490 |
|
| 3491 |
return insn; |
| 3492 |
} |
| 3493 |
|
| 3494 |
/* Make sure operands are in the right order for an addsi3 insn as |
| 3495 |
generated by a define_split. Nothing but REG_P as the first |
| 3496 |
operand is recognized by addsi3 after reload. OPERANDS contains |
| 3497 |
the operands, with the first at OPERANDS[N] and the second at |
| 3498 |
OPERANDS[N+1]. */ |
| 3499 |
|
| 3500 |
void |
| 3501 |
cris_order_for_addsi3 (rtx *operands, int n) |
| 3502 |
{ |
| 3503 |
if (!REG_P (operands[n])) |
| 3504 |
{ |
| 3505 |
rtx tem = operands[n]; |
| 3506 |
operands[n] = operands[n + 1]; |
| 3507 |
operands[n + 1] = tem; |
| 3508 |
} |
| 3509 |
} |
| 3510 |
|
| 3511 |
/* Use from within code, from e.g. PRINT_OPERAND and |
| 3512 |
PRINT_OPERAND_ADDRESS. Macros used in output_addr_const need to emit |
| 3513 |
different things depending on whether code operand or constant is |
| 3514 |
emitted. */ |
| 3515 |
|
| 3516 |
static void |
| 3517 |
cris_output_addr_const (FILE *file, rtx x) |
| 3518 |
{ |
| 3519 |
in_code++; |
| 3520 |
output_addr_const (file, x); |
| 3521 |
in_code--; |
| 3522 |
} |
| 3523 |
|
| 3524 |
/* Worker function for ASM_OUTPUT_SYMBOL_REF. */ |
| 3525 |
|
| 3526 |
void |
| 3527 |
cris_asm_output_symbol_ref (FILE *file, rtx x) |
| 3528 |
{ |
| 3529 |
gcc_assert (GET_CODE (x) == SYMBOL_REF); |
| 3530 |
assemble_name (file, XSTR (x, 0)); |
| 3531 |
} |
| 3532 |
|
| 3533 |
/* Worker function for ASM_OUTPUT_LABEL_REF. */ |
| 3534 |
|
| 3535 |
void |
| 3536 |
cris_asm_output_label_ref (FILE *file, char *buf) |
| 3537 |
{ |
| 3538 |
assemble_name (file, buf); |
| 3539 |
} |
| 3540 |
|
| 3541 |
/* Worker function for TARGET_STRUCT_VALUE_RTX. */ |
| 3542 |
|
| 3543 |
static rtx |
| 3544 |
cris_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED, |
| 3545 |
int incoming ATTRIBUTE_UNUSED) |
| 3546 |
{ |
| 3547 |
return gen_rtx_REG (Pmode, CRIS_STRUCT_VALUE_REGNUM); |
| 3548 |
} |
| 3549 |
|
| 3550 |
/* Worker function for TARGET_SETUP_INCOMING_VARARGS. */ |
| 3551 |
|
| 3552 |
static void |
| 3553 |
cris_setup_incoming_varargs (cumulative_args_t ca_v, |
| 3554 |
const function_arg_info &, |
| 3555 |
int *pretend_arg_size, |
| 3556 |
int second_time) |
| 3557 |
{ |
| 3558 |
CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v); |
| 3559 |
|
| 3560 |
if (ca->regs < CRIS_MAX_ARGS_IN_REGS) |
| 3561 |
{ |
| 3562 |
int stdarg_regs = CRIS_MAX_ARGS_IN_REGS - ca->regs; |
| 3563 |
cfun->machine->stdarg_regs = stdarg_regs; |
| 3564 |
*pretend_arg_size = stdarg_regs * 4; |
| 3565 |
} |
| 3566 |
|
| 3567 |
if (TARGET_PDEBUG) |
| 3568 |
fprintf (asm_out_file, |
| 3569 |
"\n; VA:: ANSI: %d args before, anon @ #%d, %dtime\n", |
| 3570 |
ca->regs, *pretend_arg_size, second_time); |
| 3571 |
} |
| 3572 |
|
| 3573 |
/* Return true if ARG must be passed by invisible reference. |
| 3574 |
For cris, we pass <= 8 bytes by value, others by reference. */ |
| 3575 |
|
| 3576 |
static bool |
| 3577 |
cris_pass_by_reference (cumulative_args_t, const function_arg_info &arg) |
| 3578 |
{ |
| 3579 |
return (targetm.calls.must_pass_in_stack (arg) |
| 3580 |
|| CRIS_FUNCTION_ARG_SIZE (arg.mode, arg.type) > 8); |
| 3581 |
} |
| 3582 |
|
| 3583 |
/* A combination of defining TARGET_PROMOTE_FUNCTION_MODE, promoting arguments |
| 3584 |
and *not* defining TARGET_PROMOTE_PROTOTYPES or PROMOTE_MODE gives the |
| 3585 |
best code size and speed for gcc, ipps and products in gcc-2.7.2. */ |
| 3586 |
|
| 3587 |
machine_mode |
| 3588 |
cris_promote_function_mode (const_tree type ATTRIBUTE_UNUSED, |
| 3589 |
machine_mode mode, |
| 3590 |
int *punsignedp ATTRIBUTE_UNUSED, |
| 3591 |
const_tree fntype ATTRIBUTE_UNUSED, |
| 3592 |
int for_return) |
| 3593 |
{ |
| 3594 |
/* Defining PROMOTE_FUNCTION_RETURN in gcc-2.7.2 uncovered bug 981110 (even |
| 3595 |
when modifying TARGET_FUNCTION_VALUE to return the promoted mode). |
| 3596 |
Maybe pointless as of now, but let's keep the old behavior. */ |
| 3597 |
if (for_return == 1) |
| 3598 |
return mode; |
| 3599 |
return CRIS_PROMOTED_MODE (mode, *punsignedp, type); |
| 3600 |
} |
| 3601 |
|
| 3602 |
/* Atomic types require alignment to be at least their "natural" size. */ |
| 3603 |
|
| 3604 |
static unsigned int |
| 3605 |
cris_atomic_align_for_mode (machine_mode mode) |
| 3606 |
{ |
| 3607 |
return GET_MODE_BITSIZE (mode); |
| 3608 |
} |
| 3609 |
|
| 3610 |
/* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the |
| 3611 |
time being. */ |
| 3612 |
|
| 3613 |
static rtx |
| 3614 |
cris_function_value(const_tree type, |
| 3615 |
const_tree func ATTRIBUTE_UNUSED, |
| 3616 |
bool outgoing ATTRIBUTE_UNUSED) |
| 3617 |
{ |
| 3618 |
return gen_rtx_REG (TYPE_MODE (type), CRIS_FIRST_ARG_REG); |
| 3619 |
} |
| 3620 |
|
| 3621 |
/* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the |
| 3622 |
time being. */ |
| 3623 |
|
| 3624 |
static rtx |
| 3625 |
cris_libcall_value (machine_mode mode, |
| 3626 |
const_rtx fun ATTRIBUTE_UNUSED) |
| 3627 |
{ |
| 3628 |
return gen_rtx_REG (mode, CRIS_FIRST_ARG_REG); |
| 3629 |
} |
| 3630 |
|
| 3631 |
/* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the |
| 3632 |
time being. */ |
| 3633 |
|
| 3634 |
static bool |
| 3635 |
cris_function_value_regno_p (const unsigned int regno) |
| 3636 |
{ |
| 3637 |
return (regno == CRIS_FIRST_ARG_REG); |
| 3638 |
} |
| 3639 |
|
| 3640 |
static int |
| 3641 |
cris_arg_partial_bytes (cumulative_args_t ca, const function_arg_info &arg) |
| 3642 |
{ |
| 3643 |
if (get_cumulative_args (ca)->regs == CRIS_MAX_ARGS_IN_REGS - 1 |
| 3644 |
&& !targetm.calls.must_pass_in_stack (arg) |
| 3645 |
&& CRIS_FUNCTION_ARG_SIZE (arg.mode, arg.type) > 4 |
| 3646 |
&& CRIS_FUNCTION_ARG_SIZE (arg.mode, arg.type) <= 8) |
| 3647 |
return UNITS_PER_WORD; |
| 3648 |
else |
| 3649 |
return 0; |
| 3650 |
} |
| 3651 |
|
| 3652 |
static rtx |
| 3653 |
cris_function_arg_1 (cumulative_args_t ca_v, const function_arg_info &arg, |
| 3654 |
bool incoming) |
| 3655 |
{ |
| 3656 |
const CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v); |
| 3657 |
|
| 3658 |
if ((!incoming || arg.named) && ca->regs < CRIS_MAX_ARGS_IN_REGS) |
| 3659 |
return gen_rtx_REG (arg.mode, CRIS_FIRST_ARG_REG + ca->regs); |
| 3660 |
else |
| 3661 |
return NULL_RTX; |
| 3662 |
} |
| 3663 |
|
| 3664 |
/* Worker function for TARGET_FUNCTION_ARG. |
| 3665 |
The void_type_node is sent as a "closing" call. */ |
| 3666 |
|
| 3667 |
static rtx |
| 3668 |
cris_function_arg (cumulative_args_t ca, const function_arg_info &arg) |
| 3669 |
{ |
| 3670 |
return cris_function_arg_1 (ca, arg, false); |
| 3671 |
} |
| 3672 |
|
| 3673 |
/* Worker function for TARGET_FUNCTION_INCOMING_ARG. |
| 3674 |
|
| 3675 |
The differences between this and the previous, is that this one checks |
| 3676 |
that an argument is named, since incoming stdarg/varargs arguments are |
| 3677 |
pushed onto the stack, and we don't have to check against the "closing" |
| 3678 |
function_arg_info::end_marker parameter. */ |
| 3679 |
|
| 3680 |
static rtx |
| 3681 |
cris_function_incoming_arg (cumulative_args_t ca, const function_arg_info &arg) |
| 3682 |
{ |
| 3683 |
return cris_function_arg_1 (ca, arg, true); |
| 3684 |
} |
| 3685 |
|
| 3686 |
/* Worker function for TARGET_FUNCTION_ARG_ADVANCE. */ |
| 3687 |
|
| 3688 |
static void |
| 3689 |
cris_function_arg_advance (cumulative_args_t ca_v, |
| 3690 |
const function_arg_info &arg) |
| 3691 |
{ |
| 3692 |
CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v); |
| 3693 |
|
| 3694 |
ca->regs += (3 + CRIS_FUNCTION_ARG_SIZE (arg.mode, arg.type)) / 4; |
| 3695 |
} |
| 3696 |
|
| 3697 |
/* Worker function for TARGET_MD_ASM_ADJUST. */ |
| 3698 |
|
| 3699 |
static rtx_insn * |
| 3700 |
cris_md_asm_adjust (vec<rtx> &outputs, vec<rtx> &inputs, |
| 3701 |
vec<machine_mode> & /*input_modes*/, |
| 3702 |
vec<const char *> &constraints, |
| 3703 |
vec<rtx> &/*uses*/, vec<rtx> &clobbers, |
| 3704 |
HARD_REG_SET &clobbered_regs, location_t /*loc*/) |
| 3705 |
{ |
| 3706 |
/* For the time being, all asms clobber condition codes. |
| 3707 |
Revisit when there's a reasonable use for inputs/outputs |
| 3708 |
that mention condition codes. */ |
| 3709 |
clobbers.safe_push (gen_rtx_REG (CCmode, CRIS_CC0_REGNUM)); |
| 3710 |
SET_HARD_REG_BIT (clobbered_regs, CRIS_CC0_REGNUM); |
| 3711 |
|
| 3712 |
/* Determine if the source using MOF. If it is, automatically |
| 3713 |
clobbering MOF would cause it to have impossible constraints. */ |
| 3714 |
|
| 3715 |
/* Look for a use of the MOF constraint letter: h. */ |
| 3716 |
for (unsigned i = 0, n = constraints.length(); i < n; ++i) |
| 3717 |
if (strchr (constraints[i], 'h') != NULL) |
| 3718 |
return NULL; |
| 3719 |
|
| 3720 |
/* Look for an output or an input that touches MOF. */ |
| 3721 |
rtx mof_reg = gen_rtx_REG (SImode, CRIS_MOF_REGNUM); |
| 3722 |
for (unsigned i = 0, n = outputs.length(); i < n; ++i) |
| 3723 |
if (reg_overlap_mentioned_p (mof_reg, outputs[i])) |
| 3724 |
return NULL; |
| 3725 |
for (unsigned i = 0, n = inputs.length(); i < n; ++i) |
| 3726 |
if (reg_overlap_mentioned_p (mof_reg, inputs[i])) |
| 3727 |
return NULL; |
| 3728 |
|
| 3729 |
/* No direct reference to MOF or its constraint. |
| 3730 |
Clobber it for backward compatibility. */ |
| 3731 |
clobbers.safe_push (mof_reg); |
| 3732 |
SET_HARD_REG_BIT (clobbered_regs, CRIS_MOF_REGNUM); |
| 3733 |
return NULL; |
| 3734 |
} |
| 3735 |
|
| 3736 |
/* Implement TARGET_FRAME_POINTER_REQUIRED. |
| 3737 |
|
| 3738 |
Really only needed if the stack frame has variable length (alloca |
| 3739 |
or variable sized local arguments (GNU C extension). See PR39499 and |
| 3740 |
PR38609 for the reason this isn't just 0. */ |
| 3741 |
|
| 3742 |
bool |
| 3743 |
cris_frame_pointer_required (void) |
| 3744 |
{ |
| 3745 |
return !crtl->sp_is_unchanging; |
| 3746 |
} |
| 3747 |
|
| 3748 |
/* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE. |
| 3749 |
|
| 3750 |
This looks too complicated, and it is. I assigned r7 to be the |
| 3751 |
static chain register, but it is call-saved, so we have to save it, |
| 3752 |
and come back to restore it after the call, so we have to save srp... |
| 3753 |
Anyway, trampolines are rare enough that we can cope with this |
| 3754 |
somewhat lack of elegance. |
| 3755 |
(Do not be tempted to "straighten up" whitespace in the asms; the |
| 3756 |
assembler #NO_APP state mandates strict spacing). */ |
| 3757 |
/* ??? See the i386 regparm=3 implementation that pushes the static |
| 3758 |
chain value to the stack in the trampoline, and uses a call-saved |
| 3759 |
register when called directly. */ |
| 3760 |
|
| 3761 |
static void |
| 3762 |
cris_asm_trampoline_template (FILE *f) |
| 3763 |
{ |
| 3764 |
fprintf (f, "\tmove.d $%s,[$pc+20]\n", reg_names[STATIC_CHAIN_REGNUM]); |
| 3765 |
fprintf (f, "\tmove $srp,[$pc+22]\n"); |
| 3766 |
fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]); |
| 3767 |
fprintf (f, "\tjsr 0\n"); |
| 3768 |
fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]); |
| 3769 |
fprintf (f, "\tjump 0\n"); |
| 3770 |
} |
| 3771 |
|
| 3772 |
/* Implement TARGET_TRAMPOLINE_INIT. */ |
| 3773 |
|
| 3774 |
static void |
| 3775 |
cris_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) |
| 3776 |
{ |
| 3777 |
rtx fnaddr = XEXP (DECL_RTL (fndecl), 0); |
| 3778 |
rtx mem; |
| 3779 |
|
| 3780 |
emit_block_move (m_tramp, assemble_trampoline_template (), |
| 3781 |
GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL); |
| 3782 |
|
| 3783 |
mem = adjust_address (m_tramp, SImode, 10); |
| 3784 |
emit_move_insn (mem, chain_value); |
| 3785 |
mem = adjust_address (m_tramp, SImode, 16); |
| 3786 |
emit_move_insn (mem, fnaddr); |
| 3787 |
|
| 3788 |
/* Note that there is no need to do anything with the cache for |
| 3789 |
sake of a trampoline. */ |
| 3790 |
} |
| 3791 |
|
| 3792 |
/* Implement TARGET_HARD_REGNO_NREGS. |
| 3793 |
|
| 3794 |
The VOIDmode test is so we can omit mode on anonymous insns. FIXME: |
| 3795 |
Still needed in 2.9x, at least for Axis-20000319. */ |
| 3796 |
|
| 3797 |
static unsigned int |
| 3798 |
cris_hard_regno_nregs (unsigned int, machine_mode mode) |
| 3799 |
{ |
| 3800 |
if (mode == VOIDmode) |
| 3801 |
return 1; |
| 3802 |
return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD); |
| 3803 |
} |
| 3804 |
|
| 3805 |
/* Implement TARGET_HARD_REGNO_MODE_OK. |
| 3806 |
|
| 3807 |
CRIS permits all registers to hold all modes. Well, except for the |
| 3808 |
condition-code register. And we can't hold larger-than-register size |
| 3809 |
modes in the last special register that can hold a full 32 bits. */ |
| 3810 |
static bool |
| 3811 |
cris_hard_regno_mode_ok (unsigned int regno, machine_mode mode) |
| 3812 |
{ |
| 3813 |
return ((mode == CCmode || regno != CRIS_CC0_REGNUM) |
| 3814 |
&& (GET_MODE_SIZE (mode) <= UNITS_PER_WORD |
| 3815 |
|| regno != CRIS_MOF_REGNUM)); |
| 3816 |
} |
| 3817 |
|
| 3818 |
/* Return the preferred minimum alignment for a static object. */ |
| 3819 |
|
| 3820 |
static HOST_WIDE_INT |
| 3821 |
cris_preferred_minimum_alignment (void) |
| 3822 |
{ |
| 3823 |
if (!TARGET_CONST_ALIGN) |
| 3824 |
return 8; |
| 3825 |
if (TARGET_ALIGN_BY_32) |
| 3826 |
return 32; |
| 3827 |
return 16; |
| 3828 |
} |
| 3829 |
|
| 3830 |
/* Implement TARGET_STATIC_RTX_ALIGNMENT. */ |
| 3831 |
|
| 3832 |
static HOST_WIDE_INT |
| 3833 |
cris_static_rtx_alignment (machine_mode mode) |
| 3834 |
{ |
| 3835 |
return MAX (cris_preferred_minimum_alignment (), GET_MODE_ALIGNMENT (mode)); |
| 3836 |
} |
| 3837 |
|
| 3838 |
/* Implement TARGET_CONSTANT_ALIGNMENT. Note that this hook has the |
| 3839 |
effect of making gcc believe that ALL references to constant stuff |
| 3840 |
(in code segment, like strings) have this alignment. That is a rather |
| 3841 |
rushed assumption. Luckily we do not care about the "alignment" |
| 3842 |
operand to builtin memcpy (only place where it counts), so it doesn't |
| 3843 |
affect any bad spots. */ |
| 3844 |
|
| 3845 |
static HOST_WIDE_INT |
| 3846 |
cris_constant_alignment (const_tree, HOST_WIDE_INT basic_align) |
| 3847 |
{ |
| 3848 |
return MAX (cris_preferred_minimum_alignment (), basic_align); |
| 3849 |
} |
| 3850 |
|
| 3851 |
#if 0 |
| 3852 |
/* Various small functions to replace macros. Only called from a |
| 3853 |
debugger. They might collide with gcc functions or system functions, |
| 3854 |
so only emit them when '#if 1' above. */ |
| 3855 |
|
| 3856 |
enum rtx_code Get_code (rtx); |
| 3857 |
|
| 3858 |
enum rtx_code |
| 3859 |
Get_code (rtx x) |
| 3860 |
{ |
| 3861 |
return GET_CODE (x); |
| 3862 |
} |
| 3863 |
|
| 3864 |
const char *Get_mode (rtx); |
| 3865 |
|
| 3866 |
const char * |
| 3867 |
Get_mode (rtx x) |
| 3868 |
{ |
| 3869 |
return GET_MODE_NAME (GET_MODE (x)); |
| 3870 |
} |
| 3871 |
|
| 3872 |
rtx Xexp (rtx, int); |
| 3873 |
|
| 3874 |
rtx |
| 3875 |
Xexp (rtx x, int n) |
| 3876 |
{ |
| 3877 |
return XEXP (x, n); |
| 3878 |
} |
| 3879 |
|
| 3880 |
rtx Xvecexp (rtx, int, int); |
| 3881 |
|
| 3882 |
rtx |
| 3883 |
Xvecexp (rtx x, int n, int m) |
| 3884 |
{ |
| 3885 |
return XVECEXP (x, n, m); |
| 3886 |
} |
| 3887 |
|
| 3888 |
int Get_rtx_len (rtx); |
| 3889 |
|
| 3890 |
int |
| 3891 |
Get_rtx_len (rtx x) |
| 3892 |
{ |
| 3893 |
return GET_RTX_LENGTH (GET_CODE (x)); |
| 3894 |
} |
| 3895 |
|
| 3896 |
/* Use upper-case to distinguish from local variables that are sometimes |
| 3897 |
called next_insn and prev_insn. */ |
| 3898 |
|
| 3899 |
rtx Next_insn (rtx); |
| 3900 |
|
| 3901 |
rtx |
| 3902 |
Next_insn (rtx insn) |
| 3903 |
{ |
| 3904 |
return NEXT_INSN (insn); |
| 3905 |
} |
| 3906 |
|
| 3907 |
rtx Prev_insn (rtx); |
| 3908 |
|
| 3909 |
rtx |
| 3910 |
Prev_insn (rtx insn) |
| 3911 |
{ |
| 3912 |
return PREV_INSN (insn); |
| 3913 |
} |
| 3914 |
#endif |
| 3915 |
|
| 3916 |
#include "gt-cris.h" |
| 3917 |
|
| 3918 |
/* |
| 3919 |
* Local variables: |
| 3920 |
* eval: (c-set-style "gnu") |
| 3921 |
* indent-tabs-mode: t |
| 3922 |
* End: |
| 3923 |
*/ |