1 /* Definitions for GCC. Part of the machine description for CRIS.
2 Copyright (C) 1998-2024 Free Software Foundation, Inc.
3 Contributed by Axis Communications. Written by Hans-Peter Nilsson.
5 This file is part of GCC.
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)
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.
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/>. */
21 #define IN_TARGET_CODE 1
25 #include "coretypes.h"
30 #include "stringpool.h"
41 #include "diagnostic-core.h"
42 #include "conditions.h"
43 #include "insn-attr.h"
46 #include "stor-layout.h"
52 #include "tm-constrs.h"
55 #include "tree-pass.h"
58 /* This file should be included last. */
59 #include "target-def.h"
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")
66 #define LOSE_AND_RETURN(msgid, x) \
69 cris_operand_lossage (msgid, x); \
73 enum cris_retinsn_type
74 { CRIS_RETINSN_UNKNOWN
= 0, CRIS_RETINSN_RET
, CRIS_RETINSN_JUMP
};
76 /* Per-function machine data. */
77 struct GTY(()) machine_function
79 int needs_return_address_on_stack
;
81 /* This is the number of registers we save in the prologue due to
85 enum cris_retinsn_type return_type
;
88 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
90 static char cris_output_insn_is_bound
= 0;
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;
96 static machine_mode
cris_promote_function_mode (const_tree
, machine_mode
,
97 int *, const_tree
, int);
99 static unsigned int cris_atomic_align_for_mode (machine_mode
);
101 static void cris_print_base (rtx
, FILE *);
103 static void cris_print_index (rtx
, FILE *);
105 static void cris_output_addr_const (FILE *, rtx
);
107 static struct machine_function
* cris_init_machine_status (void);
109 static rtx
cris_struct_value_rtx (tree
, int);
111 static void cris_setup_incoming_varargs (cumulative_args_t
,
112 const function_arg_info
&,
115 static int cris_initial_frame_pointer_offset (void);
117 static void cris_operand_lossage (const char *, rtx
);
119 static int cris_reg_saved_in_regsave_area (unsigned int);
121 static void cris_print_operand (FILE *, rtx
, int);
123 static void cris_print_operand_address (FILE *, machine_mode
, rtx
);
125 static bool cris_print_operand_punct_valid_p (unsigned char code
);
127 static void cris_conditional_register_usage (void);
129 static void cris_asm_output_mi_thunk
130 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
132 static void cris_file_start (void);
133 static void cris_init_libfuncs (void);
135 static unsigned int cris_postdbr_cmpelim (void);
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
);
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
);
159 static void cris_option_override (void);
160 static void cris_option_override_after_change ();
162 static bool cris_frame_pointer_required (void);
164 static void cris_asm_trampoline_template (FILE *);
165 static void cris_trampoline_init (rtx
, tree
, rtx
);
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,
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;
181 /* This is the parsed result of the "-march=" option, if given. */
182 int cris_cpu_version
= CRIS_DEFAULT_CPU_VERSION
;
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"
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
197 #undef TARGET_ASM_UNALIGNED_SI_OP
198 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
200 #undef TARGET_ASM_UNALIGNED_DI_OP
201 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
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
210 #undef TARGET_CONDITIONAL_REGISTER_USAGE
211 #define TARGET_CONDITIONAL_REGISTER_USAGE cris_conditional_register_usage
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
218 #undef TARGET_ASM_FILE_START
219 #define TARGET_ASM_FILE_START cris_file_start
221 #undef TARGET_INIT_LIBFUNCS
222 #define TARGET_INIT_LIBFUNCS cris_init_libfuncs
224 #undef TARGET_LEGITIMATE_ADDRESS_P
225 #define TARGET_LEGITIMATE_ADDRESS_P cris_legitimate_address_p_hook
227 #undef TARGET_PREFERRED_RELOAD_CLASS
228 #define TARGET_PREFERRED_RELOAD_CLASS cris_preferred_reload_class
230 #undef TARGET_SPILL_CLASS
231 #define TARGET_SPILL_CLASS cris_spill_class
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
240 #undef TARGET_CC_MODES_COMPATIBLE
241 #define TARGET_CC_MODES_COMPATIBLE cris_cc_modes_compatible
243 #undef TARGET_FLAGS_REGNUM
244 #define TARGET_FLAGS_REGNUM CRIS_CC0_REGNUM
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
255 #undef TARGET_PROMOTE_FUNCTION_MODE
256 #define TARGET_PROMOTE_FUNCTION_MODE cris_promote_function_mode
258 #undef TARGET_ATOMIC_ALIGN_FOR_MODE
259 #define TARGET_ATOMIC_ALIGN_FOR_MODE cris_atomic_align_for_mode
261 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
262 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
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
281 #undef TARGET_FRAME_POINTER_REQUIRED
282 #define TARGET_FRAME_POINTER_REQUIRED cris_frame_pointer_required
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
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
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
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
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
311 struct gcc_target targetm
= TARGET_INITIALIZER
;
315 const pass_data pass_data_cris_postdbr_cmpelim
=
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 */
328 class pass_cris_postdbr_cmpelim
: public rtl_opt_pass
331 pass_cris_postdbr_cmpelim (gcc::context
*ctxt
)
332 : rtl_opt_pass (pass_data_cris_postdbr_cmpelim
, ctxt
)
335 /* opt_pass methods: */
336 virtual unsigned int execute (function
*)
338 return cris_postdbr_cmpelim ();
341 /* No use running this if reorg and cmpelim aren't both run. */
342 virtual bool gate (function
*)
346 && flag_delayed_branch
347 && flag_compare_elim_after_reload
;
354 make_pass_cris_postdbr_cmpelim (gcc::context
*ctxt
)
356 return new pass_cris_postdbr_cmpelim (ctxt
);
359 /* "Cheap version" of cmpelim, making use of the opportunities opened up
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.
369 Also, reorg isn't up to date regarding data-flow handling, so we
370 can't go beyond classic RTL scanning. */
373 cris_postdbr_cmpelim ()
377 rtx_insn
*prev_cc_setter
= 0;
378 rtx_insn
*prev_cc_outer
= 0;
379 rtx dccr
= gen_rtx_REG (CCmode
, CRIS_CC0_REGNUM
);
381 /* Now look for compares in the insn stream. */
382 for (insn
= get_insns (); insn
; insn
= next
)
384 rtx_insn
*outer_insn
= insn
;
386 next
= NEXT_INSN (outer_insn
);
388 /* Forget previous state when we see a label; we can't track or
396 if (!NONDEBUG_INSN_P (insn
))
398 rtx pat
= PATTERN (insn
);
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
)
408 rtx dest
= SET_DEST (pat
);
409 rtx src
= SET_SRC (pat
);
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)
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
);
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
)))
440 machine_mode ccmode
= GET_MODE (src
);
441 rtx modeadjusted_dccr
442 = (ccmode
== CCmode
? dccr
443 : gen_rtx_REG (ccmode
, CRIS_CC0_REGNUM
));
445 /* We don't need to copy_rtx pat: we're going to
448 : gen_rtx_SET (modeadjusted_dccr
,
449 gen_rtx_COMPARE (ccmode
,
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);
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);
468 if (apply_change_group ())
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.
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
489 if (reg_set_p (dccr
, insn
))
491 rtx pat
= PATTERN (insn
);
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
)
502 prev_cc_setter
= insn
;
503 prev_cc_outer
= outer_insn
;
511 /* Helper for cris_load_multiple_op and cris_ret_movem_op. */
514 cris_movem_load_rest_p (rtx op
)
516 unsigned int reg_count
= XVECLEN (op
, 0);
522 unsigned int regno
= 0;
524 /* Perform a quick check so we don't blow up below. FIXME: Adjust for
525 other than (MEM reg). */
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))))
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
)
536 rtx reg
= XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 0);
537 rtx inc
= XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1);
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)
554 regno
= reg_count
- 1;
556 elt
= XVECEXP (op
, 0, 0);
557 src_addr
= XEXP (SET_SRC (elt
), 0);
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
))
568 for (setno
= 1; i
< XVECLEN (op
, 0); setno
++, i
++)
570 rtx elt
= XVECEXP (op
, 0, i
);
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)
589 /* Worker function for predicate for the parallel contents in a movem
593 cris_store_multiple_op_p (rtx op
)
595 int reg_count
= XVECLEN (op
, 0);
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)). */
611 elt
= XVECEXP (op
, 0, 0);
613 if (GET_CODE (elt
) != SET
)
616 dest
= SET_DEST (elt
);
618 if (!REG_P (SET_SRC (elt
)) || !MEM_P (dest
))
621 dest_addr
= XEXP (dest
, 0);
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
)
627 rtx reg
= XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 0);
628 rtx inc
= XEXP (SET_SRC (XVECEXP (op
, 0, 1)), 1);
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
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
))))
655 regno
= reg_count
- 1;
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
)
665 if (REG_P (dest_addr
))
667 dest_base
= dest_addr
;
670 else if (GET_CODE (dest_addr
) == PLUS
671 && REG_P (XEXP (dest_addr
, 0))
672 && CONST_INT_P (XEXP (dest_addr
, 1)))
674 dest_base
= XEXP (dest_addr
, 0);
675 offset
= INTVAL (XEXP (dest_addr
, 1));
680 for (setno
= 1; i
< XVECLEN (op
, 0); setno
++, i
++)
682 rtx elt
= XVECEXP (op
, 0, i
);
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
)
701 /* The TARGET_CONDITIONAL_REGISTER_USAGE worker. */
704 cris_conditional_register_usage (void)
706 if (TARGET_HAS_MUL_INSNS
)
707 fixed_regs
[CRIS_MOF_REGNUM
] = 0;
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";
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
722 cris_output_insn_is_bound
= 0;
723 switch (GET_CODE (x
))
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
736 internal_error ("MULT case in %<cris_op_str%>");
764 /* Used to control the sign/zero-extend character for the 'E' modifier.
766 cris_output_insn_is_bound
= 1;
770 return "Unknown operator";
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. */
780 cris_operand_lossage (const char *msgid
, rtx op
)
783 output_operand_lossage ("%s", msgid
);
786 /* Print an index part of an address to file. */
789 cris_print_index (rtx index
, FILE *file
)
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)
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
)
802 fprintf (file
, "$%s.",
803 reg_names
[REGNO (XEXP (index
, 0))]);
805 putc (INTVAL (XEXP (index
, 1)) == 2 ? 'w' : 'd', file
);
807 else if (GET_CODE (index
) == SIGN_EXTEND
&& MEM_P (XEXP (index
, 0)))
809 rtx inner
= XEXP (index
, 0);
810 rtx inner_inner
= XEXP (inner
, 0);
812 if (GET_CODE (inner_inner
) == POST_INC
)
814 fprintf (file
, "[$%s+].",
815 reg_names
[REGNO (XEXP (inner_inner
, 0))]);
816 putc (GET_MODE (inner
) == HImode
? 'w' : 'b', file
);
820 fprintf (file
, "[$%s].", reg_names
[REGNO (inner_inner
)]);
822 putc (GET_MODE (inner
) == HImode
? 'w' : 'b', file
);
825 else if (MEM_P (index
))
827 rtx inner
= XEXP (index
, 0);
828 if (GET_CODE (inner
) == POST_INC
)
829 fprintf (file
, "[$%s+].d", reg_names
[REGNO (XEXP (inner
, 0))]);
831 fprintf (file
, "[$%s].d", reg_names
[REGNO (inner
)]);
834 cris_operand_lossage ("unexpected index-type in cris_print_index",
838 /* Print a base rtx of an address to file. */
841 cris_print_base (rtx base
, FILE *file
)
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))]);
848 cris_operand_lossage ("unexpected base-type in cris_print_base",
852 /* Usable as a guard in expressions. */
855 cris_fatal (char *arg
)
857 internal_error (arg
);
859 /* We'll never get here; this is just to appease compilers. */
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. */
870 cris_reg_saved_in_regsave_area (unsigned int regno
)
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)));
884 /* The PRINT_OPERAND worker. */
887 cris_print_operand (FILE *file
, rtx x
, int code
)
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. */
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));
909 /* Print assembler code for operator. */
910 fprintf (file
, "%s", cris_op_str (operand
));
915 /* A movem modifier working on a parallel; output the register
919 if (GET_CODE (x
) != PARALLEL
)
920 LOSE_AND_RETURN ("invalid operand for 'o' modifier", x
);
922 /* The second item can be (set reg (plus reg const)) to denote a
925 = (GET_CODE (SET_SRC (XVECEXP (x
, 0, 1))) == PLUS
927 : XVECLEN (x
, 0) - 1);
929 fprintf (file
, "$%s", reg_names
[regno
]);
935 /* A similar movem modifier; output the memory operand. */
938 if (GET_CODE (x
) != PARALLEL
)
939 LOSE_AND_RETURN ("invalid operand for 'O' modifier", x
);
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);
947 /* The second item can be a (set reg (plus reg const)) to denote
949 if (GET_CODE (SET_SRC (XVECEXP (x
, 0, 1))) == PLUS
)
951 /* It's a post-increment, if the address is a naked (reg). */
953 addr
= gen_rtx_POST_INC (SImode
, addr
);
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)));
965 output_address (VOIDmode
, addr
);
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
)));
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
))
985 if (INTVAL (x
) <= 255)
987 else if (INTVAL (x
) <= 65535)
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. */
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
);
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
);
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
1034 fputs (optimize_size
1035 ? ".p2alignw 2,0x050f\n\t"
1036 : ".p2alignw 5,0x050f,2\n\t", file
);
1040 /* Print high (most significant) part of something. */
1041 switch (GET_CODE (operand
))
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
)));
1051 /* High part of a long long constant. */
1052 if (GET_MODE (operand
) == VOIDmode
)
1054 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, CONST_DOUBLE_HIGH (x
));
1058 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x
);
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]);
1073 /* Adjust memory address to high part. */
1075 rtx adj_mem
= operand
;
1077 = GET_MODE_BITSIZE (GET_MODE (operand
)) / BITS_PER_UNIT
;
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
)
1085 = adjust_address (adj_mem
, GET_MODE (adj_mem
), size
/ 2);
1087 output_address (VOIDmode
, XEXP (adj_mem
, 0));
1092 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x
);
1096 /* Strip the MEM expression. */
1097 operand
= XEXP (operand
, 0);
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;
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
);
1114 if (cris_output_insn_is_bound
)
1116 cris_output_insn_is_bound
= 0;
1120 putc (GET_CODE (operand
) == SIGN_EXTEND
1121 || (CONST_INT_P (operand
) && INTVAL (operand
) < 0)
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');
1134 /* Print the least significant part of operand. */
1135 if (GET_CODE (operand
) == CONST_DOUBLE
)
1137 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, CONST_DOUBLE_LOW (x
));
1140 else if (HOST_BITS_PER_WIDE_INT
> 32 && CONST_INT_P (operand
))
1142 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
,
1143 INTVAL (x
) & ((unsigned int) 0x7fffffff * 2 + 1));
1146 /* Otherwise the least significant part equals the normal part,
1147 so handle it normally. */
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");
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
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
))
1171 fprintf (file
, "Add.d ");
1173 /* Deal with printing the operand by dropping through to the
1180 gcc_assert (CONST_INT_P (operand
));
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
);
1188 fprintf (file
, "Subq %d", -val
);
1190 fprintf (file
, "Addq %d", val
);
1191 else if (val
<= 65535)
1192 fprintf (file
, "Addu.w %d", val
);
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");
1202 fprintf (file
, ".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");
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
);
1221 /* Print the size letter for an operand to a ASHIFT, which must be a
1222 const_int with a suitable value. */
1225 if (!CONST_INT_P (operand
))
1226 LOSE_AND_RETURN ("invalid operand for 'T' modifier", x
);
1228 shiftval
= INTVAL (operand
);
1230 if (!(shiftval
== 1 || shiftval
== 2))
1231 LOSE_AND_RETURN ("invalid operand for 'T' modifier", x
);
1233 fprintf (file
, "%s", shiftval
== 1 ? ".w" : ".d");
1238 /* No code, print as usual. */
1242 LOSE_AND_RETURN ("invalid operand modifier letter", x
);
1245 /* Print an operand as without a modifier letter. */
1246 switch (GET_CODE (operand
))
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
)]);
1258 output_address (GET_MODE (operand
), XEXP (operand
, 0));
1262 if (GET_MODE (operand
) == VOIDmode
)
1263 /* A long long constant. */
1264 output_addr_const (file
, operand
);
1267 /* Only single precision is allowed as plain operands the
1271 /* FIXME: Perhaps check overflow of the "single". */
1272 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (operand
), l
);
1274 fprintf (file
, "0x%lx", l
);
1279 cris_output_addr_const (file
, operand
);
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);
1292 || (!CONST_INT_P (XEXP (operand
, 0))
1293 && !CONST_INT_P (XEXP (operand
, 1))))
1294 LOSE_AND_RETURN ("unexpected multiplicative operand", x
);
1296 cris_print_base (reg
, file
);
1297 fprintf (file
, ".%c",
1298 i
== 0 || (i
== 1 && GET_CODE (operand
) == MULT
) ? 'b'
1300 : (i
== 2 && GET_CODE (operand
) == MULT
) || i
== 1 ? 'w'
1306 /* No need to handle all strange variants, let output_addr_const
1308 if (CONSTANT_P (operand
))
1310 cris_output_addr_const (file
, operand
);
1314 LOSE_AND_RETURN ("unexpected operand", x
);
1319 cris_print_operand_punct_valid_p (unsigned char code
)
1321 return (code
== '#' || code
== '!');
1324 /* The PRINT_OPERAND_ADDRESS worker. */
1327 cris_print_operand_address (FILE *file
, machine_mode
/*mode*/, rtx x
)
1329 /* All these were inside MEM:s so output indirection characters. */
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
)
1342 if (cris_base_p (x1
, true))
1344 cris_print_base (x1
, file
);
1345 cris_print_index (x2
, file
);
1347 else if (cris_base_p (x2
, true))
1349 cris_print_base (x2
, file
);
1350 cris_print_index (x1
, file
);
1353 LOSE_AND_RETURN ("unrecognized address", x
);
1357 /* A DIP. Output more indirection characters. */
1359 cris_print_base (XEXP (x
, 0), file
);
1363 LOSE_AND_RETURN ("unrecognized address", x
);
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. */
1377 cris_return_addr_rtx (int count
, rtx frameaddr ATTRIBUTE_UNUSED
)
1379 cfun
->machine
->needs_return_address_on_stack
= 1;
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. */
1385 ? gen_rtx_MEM (Pmode
, plus_constant (Pmode
, virtual_incoming_args_rtx
, -4))
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
1397 cris_eh_return_handler_rtx ()
1399 rtx ret
= cris_return_addr_rtx (0, NULL_RTX
);
1400 gcc_assert (MEM_P (ret
));
1401 MEM_VOLATILE_P (ret
) = true;
1405 /* Accessor used in cris.md:return because cfun->machine isn't available
1409 cris_return_address_on_stack (void)
1411 return df_regs_ever_live_p (CRIS_SRP_REGNUM
)
1412 || cfun
->machine
->needs_return_address_on_stack
;
1415 /* Accessor used in cris.md:return because cfun->machine isn't available
1419 cris_return_address_on_stack_for_return (void)
1421 return cfun
->machine
->return_type
== CRIS_RETINSN_RET
? false
1422 : cris_return_address_on_stack ();
1425 /* This handles FP -> SP elimination offset. */
1428 cris_initial_frame_pointer_offset (void)
1432 /* Initial offset is 0 if we don't have a frame pointer. */
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
))
1440 /* And then, last, we add the locals allocated. */
1441 offs
+= get_frame_size ();
1443 /* And more; the accumulated args size. */
1444 offs
+= crtl
->outgoing_args_size
;
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;
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. */
1459 cris_initial_elimination_offset (int fromreg
, int toreg
)
1462 = cris_initial_frame_pointer_offset ();
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 ();
1468 /* Here we act as if the frame-pointer were needed. */
1469 int ap_fp_offset
= 4 + (return_address_on_stack
? 4 : 0);
1471 if (fromreg
== ARG_POINTER_REGNUM
1472 && toreg
== HARD_FRAME_POINTER_REGNUM
)
1473 return ap_fp_offset
;
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
;
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;
1486 if (fromreg
== FRAME_POINTER_REGNUM
1487 && toreg
== HARD_FRAME_POINTER_REGNUM
)
1493 /* Nonzero if X is a hard reg that can be used as an index. */
1495 reg_ok_for_base_p (const_rtx x
, bool strict
)
1497 return ((! strict
&& ! HARD_REGISTER_P (x
))
1498 || REGNO_OK_FOR_BASE_P (REGNO (x
)));
1501 /* Nonzero if X is a hard reg that can be used as an index. */
1503 reg_ok_for_index_p (const_rtx x
, bool strict
)
1505 return reg_ok_for_base_p (x
, strict
);
1508 /* True if X is a valid base register. */
1511 cris_base_p (const_rtx x
, bool strict
)
1513 return (REG_P (x
) && reg_ok_for_base_p (x
, strict
));
1516 /* True if X is a valid index register. */
1519 cris_index_p (const_rtx x
, bool strict
)
1521 return (REG_P (x
) && reg_ok_for_index_p (x
, strict
));
1524 /* True if X is a valid base register with or without autoincrement. */
1527 cris_base_or_autoincr_p (const_rtx x
, bool strict
)
1529 return (cris_base_p (x
, strict
)
1530 || (GET_CODE (x
) == POST_INC
1531 && cris_base_p (XEXP (x
, 0), strict
)));
1534 /* True if X is a valid (register) index for BDAP, i.e. [Rs].S or [Rs+].S. */
1537 cris_bdap_index_p (const_rtx x
, bool strict
)
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
)));
1549 /* True if X is a valid (register) index for BIAP, i.e. Rd.m. */
1552 cris_biap_index_p (const_rtx x
, bool strict
)
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
)));
1560 /* Worker function for TARGET_LEGITIMATE_ADDRESS_P. */
1563 cris_legitimate_address_p_hook (machine_mode mode
, rtx x
, bool strict
,
1566 return cris_legitimate_address_p (mode
, x
, strict
);
1570 cris_legitimate_address_p (machine_mode mode
, rtx x
, bool strict
)
1574 if (cris_base_or_autoincr_p (x
, strict
))
1576 else if (CONSTANT_P (x
))
1579 else if (GET_CODE (x
) == PLUS
)
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
))
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
)))))
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
))
1610 /* Worker function for LEGITIMIZE_RELOAD_ADDRESS. */
1613 cris_reload_address_legitimized (rtx x
,
1614 machine_mode mode ATTRIBUTE_UNUSED
,
1615 int opnum ATTRIBUTE_UNUSED
,
1617 int ind_levels ATTRIBUTE_UNUSED
)
1619 enum reload_type type
= (enum reload_type
) itype
;
1623 if (GET_CODE (x
) != PLUS
)
1628 op1p
= &XEXP (x
, 1);
1633 if (GET_CODE (op0
) == SIGN_EXTEND
&& MEM_P (XEXP (op0
, 0)))
1635 rtx op00
= XEXP (op0
, 0);
1636 rtx op000
= XEXP (op00
, 0);
1637 rtx
*op000p
= &XEXP (op00
, 0);
1639 if ((GET_MODE (op00
) == HImode
|| GET_MODE (op00
) == QImode
)
1641 || (GET_CODE (op000
) == POST_INC
&& REG_P (XEXP (op000
, 0)))))
1643 bool something_reloaded
= false;
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. */
1655 && REGNO (op000
) > CRIS_LAST_GENERAL_REGISTER
))
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;
1664 if (REGNO (op1
) > CRIS_LAST_GENERAL_REGISTER
)
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,
1670 something_reloaded
= true;
1673 gcc_assert (something_reloaded
);
1683 /* Worker function for TARGET_PREFERRED_RELOAD_CLASS.
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
1695 cris_preferred_reload_class (rtx x
, reg_class_t rclass
)
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
;
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
))
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
))
1718 /* Worker function for TARGET_SPILL_CLASS. */
1721 cris_spill_class (reg_class_t
/* orig_class */, machine_mode
)
1726 /* Worker function for TARGET_REGISTER_MOVE_COST. */
1729 cris_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
1730 reg_class_t from
, reg_class_t to
)
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. */
1738 if (reg_classes_intersect_p (from
, SPECIAL_REGS
)
1739 && reg_classes_intersect_p (to
, SPECIAL_REGS
))
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
))
1751 /* Worker function for TARGET_MEMORY_MOVE_COST.
1753 This isn't strictly correct for v0..3 in buswidth-8bit mode, but should
1757 cris_memory_move_cost (machine_mode mode
,
1758 reg_class_t rclass ATTRIBUTE_UNUSED
,
1759 bool in ATTRIBUTE_UNUSED
)
1768 /* Worker function for SELECT_CC_MODE. */
1771 cris_select_cc_mode (enum rtx_code op
, rtx x
, rtx y
)
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
);
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
)
1785 /* If we have a comparison that doesn't have to look at V or C, return
1787 if (op
== EQ
|| op
== NE
|| op
== GTU
|| op
== LEU
1788 || op
== LT
|| op
== GE
)
1791 /* We should only get here for comparison operators. */
1792 gcc_assert (op
== GEU
|| op
== LTU
|| op
== GT
|| op
== LE
);
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
1803 cris_cc_modes_compatible (machine_mode m1
, machine_mode m2
)
1805 if (m1
== CC_NZVCmode
)
1807 if (m2
== CC_NZVCmode
|| m2
== CCmode
)
1812 if (m2
== CC_NZVCmode
)
1814 if (m1
== CC_NZVCmode
|| m1
== CCmode
)
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. */
1830 cris_simple_epilogue (void)
1833 unsigned int reglimit
= STACK_POINTER_REGNUM
;
1835 if (! reload_completed
1836 || frame_pointer_needed
1837 || get_frame_size () != 0
1838 || crtl
->args
.pretend_args_size
1840 || crtl
->outgoing_args_size
1841 || crtl
->calls_eh_return
1843 /* If we're not supposed to emit prologue and epilogue, we must
1844 not emit return-type instructions. */
1845 || !TARGET_PROLOGUE_EPILOGUE
)
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
))
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
1861 cris_emit_trap_for_misalignment (rtx mem
)
1863 rtx addr
, reg
, ok_label
, andop
;
1865 int natural_alignment
;
1866 gcc_assert (MEM_P (mem
));
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 ();
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
));
1882 predict_insn_def (jmp
, PRED_NORETURN
, TAKEN
);
1883 expand_builtin_trap ();
1884 emit_label (ok_label
);
1887 /* Expand a return insn (just one insn) marked as using SRP or stack
1888 slot depending on parameter ON_STACK. */
1891 cris_expand_return (bool on_stack
)
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
);
1901 CRIS_ASSERT (cfun
->machine
->return_type
!= CRIS_RETINSN_RET
|| !on_stack
);
1902 CRIS_ASSERT (cfun
->machine
->return_type
!= CRIS_RETINSN_JUMP
|| on_stack
);
1904 cfun
->machine
->return_type
1905 = on_stack
? CRIS_RETINSN_JUMP
: CRIS_RETINSN_RET
;
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. */
1913 cris_rtx_costs (rtx x
, machine_mode mode
, int outer_code
, int opno
,
1914 int *total
, bool speed
)
1916 int code
= GET_CODE (x
);
1922 HOST_WIDE_INT val
= INTVAL (x
);
1925 else if (val
< 32 && val
>= -32)
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
1936 case MINUS
: case ASHIFT
: case LSHIFTRT
:
1937 case ASHIFTRT
: case AND
: case IOR
:
1938 if (GET_MODE_SIZE(mode
) <= UNITS_PER_WORD
)
1948 /* Eight or 16 bits are a word and cycle more expensive. */
1949 else if (val
<= 32767 && val
>= -32768)
1951 /* A 32-bit constant (or very seldom, unsigned 16 bits) costs
1952 another word. FIXME: This isn't linear to 16 bits. */
1968 if (x
!= CONST0_RTX (mode
== VOIDmode
? DImode
: mode
))
1971 /* Make 0.0 cheap, else test-insns will not be used. */
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.
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))
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))
1996 /* If we have a multiply insn, then the cost is between
1997 1 and 2 "fast" instructions. */
1998 if (TARGET_HAS_MUL_INSNS
)
2000 *total
= COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2;
2004 /* Estimate as 4 + 4 * #ofbits. */
2005 *total
= COSTS_N_INSNS (132);
2014 if (!CONST_INT_P (XEXP (x
, 1))
2015 || exact_log2 (INTVAL (XEXP (x
, 1)) < 0))
2017 /* Estimate this as 4 + 8 * #of bits. */
2018 *total
= COSTS_N_INSNS (260);
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)))
2030 = (rtx_cost (XEXP (x
, 0), mode
, (enum rtx_code
) outer_code
,
2032 + 2 * GET_MODE_NUNITS (mode
));
2038 /* Conditionals are split after reload, giving a different look. */
2039 if (reload_completed
)
2041 if (outer_code
!= COMPARE
)
2064 case ZERO_EXTEND
: case SIGN_EXTEND
:
2065 *total
= rtx_cost (XEXP (x
, 0), VOIDmode
, (enum rtx_code
) outer_code
,
2074 /* The ADDRESS_COST worker. */
2077 cris_address_cost (rtx x
, machine_mode mode ATTRIBUTE_UNUSED
,
2078 addr_space_t as ATTRIBUTE_UNUSED
,
2079 bool speed ATTRIBUTE_UNUSED
)
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. */
2091 /* The cheapest addressing modes get 0, since nothing extra is needed. */
2092 if (cris_base_or_autoincr_p (x
, false))
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. */
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. */
2105 /* Handle BIAP and BDAP prefixes. */
2106 if (GET_CODE (x
) == PLUS
)
2108 rtx tem1
= XEXP (x
, 0);
2109 rtx tem2
= XEXP (x
, 1);
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);
2116 /* We'll "assume" we have canonical RTX now. */
2117 gcc_assert (REG_P (tem1
) || GET_CODE (tem1
) == MULT
);
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))
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)
2131 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
2133 if (satisfies_constraint_L (tem2
))
2136 /* A BDAP with some other constant is 2 bytes extra. */
2137 if (CONSTANT_P (tem2
))
2138 return (2 + 2 + 2) / 2;
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;
2145 /* What else? Return a high cost. It matters only for valid
2146 addressing modes. */
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.
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. */
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
)
2170 /* Find what value to multiply with, for rx =ry + rz * n. */
2171 int mult
= multop
< 0 ? 1 : INTVAL (ops
[multop
]);
2173 rtx reg_rtx
= ops
[rreg
];
2174 rtx val_rtx
= ops
[rval
];
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
2179 if (! cris_base_p (reg_rtx
, lra_in_progress
|| reload_completed
))
2180 reg_rtx
= val_rtx
, val_rtx
= ops
[rreg
];
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
))
2187 /* Don't do this when -mno-split. */
2188 if (!TARGET_SIDE_EFFECT_PREFIXES
)
2191 /* The mult expression may be hidden in lreg. FIXME: Add more
2192 commentary about that. */
2193 if (GET_CODE (val_rtx
) == MULT
)
2195 mult
= INTVAL (XEXP (val_rtx
, 1));
2196 val_rtx
= XEXP (val_rtx
, 0);
2200 /* First check the "other operand". */
2203 if (GET_MODE_SIZE (GET_MODE (ops
[other_op
])) > UNITS_PER_WORD
)
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
]))
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
))
2224 && ! cris_base_p (val_rtx
, lra_in_progress
|| reload_completed
))
2227 /* Do not allow rx = rx + n if a normal add or sub with same size
2229 if (rtx_equal_p (ops
[lreg
], reg_rtx
)
2230 && CONST_INT_P (val_rtx
)
2231 && (INTVAL (val_rtx
) <= 63 && INTVAL (val_rtx
) >= -63))
2234 /* Check allowed cases, like [r(+)?].[bwd] and const. */
2235 if (CONSTANT_P (val_rtx
))
2239 && cris_base_or_autoincr_p (XEXP (val_rtx
, 0),
2240 lra_in_progress
|| reload_completed
))
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
))
2249 /* If we got here, it's not a valid addressing mode. */
2252 else if (code
== MULT
2254 && cris_base_p (val_rtx
,
2255 lra_in_progress
|| reload_completed
)))
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
)))
2262 /* Do not allow bad multiply-values. */
2263 if (mult
!= 1 && mult
!= 2 && mult
!= 4)
2266 /* Only allow r + ... */
2267 if (! cris_base_p (reg_rtx
, lra_in_progress
|| reload_completed
))
2270 /* If we got here, all seems ok.
2271 (All checks need to be done above). */
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");
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. */
2283 cris_asm_output_ident (const char *string
)
2285 if (symtab
->state
!= PARSING
)
2288 default_asm_output_ident_directive (string
);
2291 /* The ASM_OUTPUT_CASE_END worker. */
2294 cris_asm_output_case_end (FILE *stream
, int num
, rtx_insn
*table
)
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
));
2301 whole_jump_insn
= prev_nonnote_nondebug_insn (whole_jump_insn
);
2302 gcc_assert (whole_jump_insn
!= NULL_RTX
&& JUMP_P (whole_jump_insn
));
2304 /* Get the pattern of the casejump, so we can extract the default label. */
2305 rtx whole_jump_pat
= PATTERN (whole_jump_insn
);
2307 asm_fprintf (stream
,
2308 "\t.word %LL%d-%LL%d%s\n",
2309 CODE_LABEL_NUMBER (XEXP
2311 (XEXP (XVECEXP (whole_jump_pat
, 0, 0), 1),
2314 (TARGET_PDEBUG
? "; default" : ""));
2317 /* The TARGET_OPTION_OVERRIDE worker.
2318 As is the norm, this also parses -mfoo=bar type parameters. */
2321 cris_option_override (void)
2323 if (cris_max_stackframe_str
)
2325 cris_max_stackframe
= atoi (cris_max_stackframe_str
);
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);
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
;
2340 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2344 = (*cris_cpu_str
== 'v' ? atoi (cris_cpu_str
+ 1) : -1);
2346 if (strcmp ("etrax4", cris_cpu_str
) == 0)
2347 cris_cpu_version
= 3;
2349 if (strcmp ("svinto", cris_cpu_str
) == 0
2350 || strcmp ("etrax100", cris_cpu_str
) == 0)
2351 cris_cpu_version
= 8;
2353 if (strcmp ("ng", cris_cpu_str
) == 0
2354 || strcmp ("etrax100lx", cris_cpu_str
) == 0)
2355 cris_cpu_version
= 10;
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
);
2361 /* Set the target flags. */
2362 if (cris_cpu_version
>= CRIS_CPU_ETRAX4
)
2363 target_flags
|= MASK_ETRAX4_ADD
;
2365 /* If this is Svinto or higher, align for 32 bit accesses. */
2366 if (cris_cpu_version
>= CRIS_CPU_SVINTO
)
2368 |= (MASK_SVINTO
| MASK_ALIGN_BY_32
2369 | MASK_STACK_ALIGN
| MASK_CONST_ALIGN
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). */
2380 = (*cris_tune_str
== 'v' ? atoi (cris_tune_str
+ 1) : -1);
2382 if (strcmp ("etrax4", cris_tune_str
) == 0)
2385 if (strcmp ("svinto", cris_tune_str
) == 0
2386 || strcmp ("etrax100", cris_tune_str
) == 0)
2389 if (strcmp ("ng", cris_tune_str
) == 0
2390 || strcmp ("etrax100lx", cris_tune_str
) == 0)
2393 if (cris_tune
< 0 || cris_tune
> 32)
2394 error ("unknown CRIS cpu version specification in %<-mtune=%>: %s",
2397 if (cris_tune
>= CRIS_CPU_SVINTO
)
2398 /* We have currently nothing more to tune than alignment for
2401 |= (MASK_STACK_ALIGN
| MASK_CONST_ALIGN
2402 | MASK_DATA_ALIGN
| MASK_ALIGN_BY_32
);
2407 /* Use error rather than warning, so invalid use is easily
2408 detectable. Still change to the values we expect, to avoid
2410 error ("%<-fPIC%> and %<-fpic%> are not supported on this target");
2414 /* Set the per-function-data initializer. */
2415 init_machine_status
= cris_init_machine_status
;
2417 cris_option_override_after_change ();
2420 /* The TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE worker.
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. */
2430 cris_option_override_after_change ()
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.
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.
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;
2450 /* The TARGET_ASM_OUTPUT_MI_THUNK worker. */
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
,
2459 const char *fnname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunkdecl
));
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);
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
]);
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
]);
2474 fprintf (stream
, "\tjump ");
2475 assemble_name (stream
, XSTR (XEXP (DECL_RTL (funcdecl
), 0), 0));
2476 fprintf (stream
, "\n");
2478 final_end_function ();
2479 assemble_end_function (thunkdecl
, fnname
);
2482 /* Boilerplate emitted at start of file.
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. */
2488 cris_file_start (void)
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
);
2494 default_file_start ();
2497 /* Rename the function calls for integer multiply and divide. */
2499 cris_init_libfuncs (void)
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");
2507 /* Atomic data being unaligned is unfortunately a reality.
2509 if (TARGET_ATOMICS_MAY_CALL_LIBFUNCS
)
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");
2518 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2522 cris_init_expanders (void)
2524 /* Nothing here at the moment. */
2527 /* Zero initialization is OK for all current fields. */
2529 static struct machine_function
*
2530 cris_init_machine_status (void)
2532 return ggc_cleared_alloc
<machine_function
> ();
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. */
2539 cris_split_movdx (rtx
*operands
)
2541 machine_mode mode
= GET_MODE (operands
[0]);
2542 rtx dest
= operands
[0];
2543 rtx src
= operands
[1];
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
);
2554 int dregno
= REGNO (dest
);
2556 /* Reg-to-reg copy. */
2559 int sregno
= REGNO (src
);
2561 int reverse
= (dregno
== sregno
+ 1);
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
));
2569 emit_move_insn (operand_subword (dest
, !reverse
, TRUE
, mode
),
2570 operand_subword (src
, !reverse
, TRUE
, mode
));
2572 /* Constant-to-reg copy. */
2573 else if (CONST_INT_P (src
) || GET_CODE (src
) == CONST_DOUBLE
)
2576 split_double (src
, &words
[0], &words
[1]);
2577 emit_move_insn (operand_subword (dest
, 0, TRUE
, mode
), words
[0]);
2579 emit_move_insn (operand_subword (dest
, 1, TRUE
, mode
), words
[1]);
2581 /* Mem-to-reg copy. */
2582 else if (MEM_P (src
))
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);
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.
2594 We have two different cases here; if the addr is POST_INC,
2595 just pass it through, otherwise add constants. */
2597 if (GET_CODE (addr
) == POST_INC
)
2602 /* Whenever we emit insns with post-incremented
2603 addresses ourselves, we must add a post-inc note
2605 mem
= change_address (src
, SImode
, addr
);
2606 insn
= emit_move_insn (operand_subword (dest
, 0, TRUE
, mode
),
2608 if (GET_CODE (XEXP (mem
, 0)) == POST_INC
)
2610 = alloc_EXPR_LIST (REG_INC
, XEXP (XEXP (mem
, 0), 0),
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
)
2617 = alloc_EXPR_LIST (REG_INC
, XEXP (XEXP (mem
, 0), 0),
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
2626 if (side_effects_p (addr
))
2627 fatal_insn ("unexpected side-effects in address", addr
);
2629 emit_move_insn (operand_subword (dest
, reverse
, TRUE
, mode
),
2632 plus_constant (Pmode
, addr
,
2633 reverse
* UNITS_PER_WORD
)));
2634 emit_move_insn (operand_subword (dest
, ! reverse
, TRUE
, mode
),
2637 plus_constant (Pmode
, addr
,
2643 internal_error ("unknown src");
2645 /* Reg-to-mem copy or clear mem. */
2646 else if (MEM_P (dest
)
2648 || src
== const0_rtx
2649 || src
== CONST0_RTX (DFmode
)))
2651 rtx addr
= XEXP (dest
, 0);
2653 if (GET_CODE (addr
) == POST_INC
)
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
)
2664 = alloc_EXPR_LIST (REG_INC
, XEXP (XEXP (mem
, 0), 0),
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
)
2671 = alloc_EXPR_LIST (REG_INC
, XEXP (XEXP (mem
, 0), 0),
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
);
2682 emit_move_insn (change_address (dest
, SImode
, addr
),
2683 operand_subword (src
, 0, TRUE
, mode
));
2685 emit_move_insn (change_address (dest
, SImode
,
2686 plus_constant (Pmode
, addr
,
2688 operand_subword (src
, 1, TRUE
, mode
));
2693 internal_error ("unknown dest");
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. */
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
)
2713 int32_t ival
= (int32_t) wval
;
2714 uint32_t uval
= (uint32_t) wval
;
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
2720 && (IN_RANGE (ival
, -63 * 2, -63 - 1)
2721 || IN_RANGE (ival
, 63 + 1, 63 * 2)))
2725 int sign
= ival
< 0 ? -1 : 1;
2726 int aval
= abs (ival
);
2730 dest
= gen_rtx_REG (SImode
, REGNO (dest
));
2731 op
= gen_rtx_REG (SImode
, REGNO (op
));
2733 emit_insn (gen_addsi3 (dest
, op
, GEN_INT (63 * sign
)));
2734 emit_insn (gen_addsi3 (dest
, op
, GEN_INT ((aval
- 63) * sign
)));
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)
2751 /* Count number of leading zeros. */
2752 for (i
= 31; i
>= 0; i
--)
2754 if ((uval
& (1 << i
)) == 0)
2760 /* Count number of trailing zero's. */
2761 for (i
= 0; i
<= 31; i
++)
2763 if ((uval
& (1 << i
)) == 0)
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))
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. */
2781 dest
= gen_rtx_REG (SImode
, REGNO (dest
));
2782 op
= gen_rtx_REG (SImode
, REGNO (op
));
2786 emit_insn (gen_ashlsi3 (dest
, op
, GEN_INT (msb_zeros
)));
2787 emit_insn (gen_lshrsi3 (dest
, op
, GEN_INT (msb_zeros
)));
2791 emit_insn (gen_lshrsi3 (dest
, op
, GEN_INT (lsb_zeros
)));
2792 emit_insn (gen_ashlsi3 (dest
, op
, GEN_INT (lsb_zeros
)));
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. */
2807 cris_reduce_compare (rtx
*relp
, rtx
*, rtx
*op1p
)
2810 rtx_code code
= GET_CODE (*relp
);
2812 /* Code lifted mostly from emit_store_flag_1. */
2816 if (op1
== const1_rtx
)
2820 if (op1
== constm1_rtx
)
2824 if (op1
== const1_rtx
)
2828 if (op1
== constm1_rtx
)
2832 if (op1
== const1_rtx
)
2836 if (op1
== const1_rtx
)
2840 if (op1
== const0_rtx
)
2844 if (op1
== const0_rtx
)
2851 if (code
!= GET_CODE (*relp
))
2854 PUT_CODE (*relp
, code
);
2858 /* The expander for the prologue pattern name. */
2861 cris_expand_prologue (void)
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;
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
;
2874 /* Don't do anything if no prologues or epilogues are wanted. */
2875 if (!TARGET_PROLOGUE_EPILOGUE
)
2878 CRIS_ASSERT (size
>= 0);
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;
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
;
2896 framesize
+= pretend
;
2898 for (regno
= CRIS_FIRST_ARG_REG
+ CRIS_MAX_ARGS_IN_REGS
- 1;
2900 regno
--, pretend
-= 4, stdarg_regs
--)
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
2907 RTX_FRAME_RELATED_P (insn
) = 1;
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
));
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
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. */
2924 /* Save SRP if not a leaf function. */
2925 if (return_address_on_stack
)
2927 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
,
2928 GEN_INT (-4 - pretend
)));
2930 RTX_FRAME_RELATED_P (insn
) = 1;
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;
2939 /* Set up the frame pointer, if needed. */
2940 if (frame_pointer_needed
)
2942 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
,
2943 GEN_INT (-4 - pretend
)));
2945 RTX_FRAME_RELATED_P (insn
) = 1;
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;
2952 insn
= emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
2953 RTX_FRAME_RELATED_P (insn
) = 1;
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. */
2963 /* Get a contiguous sequence of registers, starting with R0, that need
2965 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
2967 if (cris_reg_saved_in_regsave_area (regno
))
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
;
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)
2982 = (n_movem_regs
== 1) ? 1 : last_movem_reg
+ 1;
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
2994 && TARGET_SIDE_EFFECT_PREFIXES
)
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 ());
3002 = cris_emit_movem_store (mem
, GEN_INT (n_saved
),
3003 -(n_saved
* 4 + size
),
3009 = emit_insn (gen_add2_insn (stack_pointer_rtx
,
3010 GEN_INT (-(n_saved
* 4
3012 RTX_FRAME_RELATED_P (insn
) = 1;
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
),
3020 framesize
+= n_saved
* 4 + size
;
3021 last_movem_reg
= -1;
3025 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
,
3026 GEN_INT (-4 - size
)));
3027 RTX_FRAME_RELATED_P (insn
) = 1;
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;
3034 framesize
+= 4 + size
;
3040 /* Check after, if we could movem all registers. This is the normal case. */
3041 if (last_movem_reg
!= -1)
3044 = (n_movem_regs
== 1) ? 1 : last_movem_reg
+ 1;
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. */
3053 && TARGET_SIDE_EFFECT_PREFIXES
)
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);
3065 insn
= emit_insn (gen_add2_insn (stack_pointer_rtx
,
3066 GEN_INT (-(n_saved
* 4 + size
))));
3067 RTX_FRAME_RELATED_P (insn
) = 1;
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);
3074 framesize
+= n_saved
* 4 + size
;
3075 /* We have to put outgoing argument space after regs. */
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
;
3084 else if ((size
+ cfoa_size
) > 0)
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
;
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
);
3097 if (flag_stack_usage_info
)
3098 current_function_static_stack_size
= framesize
;
3101 /* The expander for the epilogue pattern. */
3104 cris_expand_epilogue (void)
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
;
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;
3118 if (!TARGET_PROLOGUE_EPILOGUE
)
3121 /* Align byte count of stack frame. */
3122 if (TARGET_STACK_ALIGN
)
3123 size
= TARGET_ALIGN_BY_32
? (size
+ 3) & ~3 : (size
+ 1) & ~1;
3125 /* Check how many saved regs we can movem. They start at r0 and must
3128 regno
< FIRST_PSEUDO_REGISTER
;
3130 if (cris_reg_saved_in_regsave_area (regno
))
3134 if (regno
== last_movem_reg
+ 1)
3135 last_movem_reg
= regno
;
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;
3145 /* Now emit "normal" move insns for all regs higher than the movem
3147 for (regno
= FIRST_PSEUDO_REGISTER
- 1;
3148 regno
> last_movem_reg
;
3150 if (cris_reg_saved_in_regsave_area (regno
))
3154 if (argspace_offset
)
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;
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
);
3169 /* Whenever we emit insns with post-incremented addresses
3170 ourselves, we must add a post-inc note manually. */
3172 = alloc_EXPR_LIST (REG_INC
, stack_pointer_rtx
, REG_NOTES (insn
));
3175 /* If we have any movem-restore, do it now. */
3176 if (last_movem_reg
!= -1)
3180 if (argspace_offset
)
3182 emit_insn (gen_add2_insn (stack_pointer_rtx
, GEN_INT (argspace_offset
)));
3183 argspace_offset
= 0;
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 ());
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
)))
3195 = alloc_EXPR_LIST (REG_INC
, stack_pointer_rtx
, REG_NOTES (insn
));
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". */
3208 /* Restore frame pointer if necessary. */
3209 if (frame_pointer_needed
)
3213 emit_insn (gen_cris_frame_deallocated_barrier ());
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
);
3221 /* Whenever we emit insns with post-incremented addresses
3222 ourselves, we must add a post-inc note manually. */
3224 = alloc_EXPR_LIST (REG_INC
, stack_pointer_rtx
, REG_NOTES (insn
));
3226 else if ((size
+ argspace_offset
) != 0)
3228 emit_insn (gen_cris_frame_deallocated_barrier ());
3230 /* If there was no frame-pointer to restore sp from, we must
3231 explicitly deallocate local variables. */
3233 /* Handle space for outgoing parameters that hasn't been handled
3235 size
+= argspace_offset
;
3237 emit_insn (gen_add2_insn (stack_pointer_rtx
, GEN_INT (size
)));
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)
3245 if (crtl
->calls_eh_return
)
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
);
3256 /* Whenever we emit insns with post-incremented addresses
3257 ourselves, we must add a post-inc note manually. */
3259 = alloc_EXPR_LIST (REG_INC
, stack_pointer_rtx
, REG_NOTES (insn
));
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);
3267 cris_expand_return (true);
3272 /* If we pushed some register parameters, then adjust the stack for
3276 /* If SRP is stored on the way, we need to restore it first. */
3277 if (return_address_on_stack
)
3280 rtx srpreg
= gen_raw_REG (SImode
, CRIS_SRP_REGNUM
);
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
);
3289 /* Whenever we emit insns with post-incremented addresses
3290 ourselves, we must add a post-inc note manually. */
3292 = alloc_EXPR_LIST (REG_INC
, stack_pointer_rtx
, REG_NOTES (insn
));
3295 emit_insn (gen_add2_insn (stack_pointer_rtx
, GEN_INT (pretend
)));
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);
3305 /* Worker function for generating movem from mem for load_multiple. */
3308 cris_gen_movem_load (rtx src
, rtx nregs_rtx
)
3310 int nregs
= INTVAL (nregs_rtx
);
3314 rtx srcreg
= XEXP (src
, 0);
3315 unsigned int regno
= nregs
- 1;
3318 if (GET_CODE (srcreg
) == POST_INC
)
3319 srcreg
= XEXP (srcreg
, 0);
3321 CRIS_ASSERT (REG_P (srcreg
));
3323 /* Don't use movem for just one insn. The insns are equivalent. */
3325 return gen_movsi (gen_rtx_REG (SImode
, 0), src
);
3327 vec
= rtvec_alloc (nregs
+ (GET_CODE (XEXP (src
, 0)) == POST_INC
));
3329 if (GET_CODE (XEXP (src
, 0)) == POST_INC
)
3332 = gen_rtx_SET (srcreg
, plus_constant (Pmode
, srcreg
, nregs
* 4));
3336 src
= replace_equiv_address (src
, srcreg
);
3338 = gen_rtx_SET (gen_rtx_REG (SImode
, regno
), src
);
3341 for (i
= 1; i
< nregs
; i
++, eltno
++)
3343 RTVEC_ELT (vec
, eltno
)
3344 = gen_rtx_SET (gen_rtx_REG (SImode
, regno
),
3345 adjust_address_nv (src
, SImode
, i
* 4));
3349 return gen_rtx_PARALLEL (VOIDmode
, vec
);
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. */
3357 cris_emit_insn (rtx x
)
3359 rtvec vec
= rtvec_alloc (2);
3361 RTVEC_ELT (vec
, 0) = x
;
3363 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CRIS_CC0_REGNUM
));
3365 return emit_insn (gen_rtx_PARALLEL (VOIDmode
, vec
));
3368 /* Worker function for generating movem to mem. If FRAME_RELATED, notes
3369 are added that the dwarf2 machinery understands. */
3372 cris_emit_movem_store (rtx dest
, rtx nregs_rtx
, int increment
,
3375 int nregs
= INTVAL (nregs_rtx
);
3380 rtx destreg
= XEXP (dest
, 0);
3381 unsigned int regno
= nregs
- 1;
3384 if (GET_CODE (destreg
) == POST_INC
)
3385 increment
+= nregs
* 4;
3387 if (GET_CODE (destreg
) == POST_INC
|| GET_CODE (destreg
) == PLUS
)
3388 destreg
= XEXP (destreg
, 0);
3390 CRIS_ASSERT (REG_P (destreg
));
3392 /* Don't use movem for just one insn. The insns are equivalent. */
3397 insn
= emit_move_insn (dest
, gen_rtx_REG (SImode
, 0));
3399 RTX_FRAME_RELATED_P (insn
) = 1;
3403 /* If there was a request for a side-effect, create the ordinary
3405 vec
= rtvec_alloc (3);
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
,
3412 = gen_rtx_CLOBBER (VOIDmode
, gen_rtx_REG (CCmode
, CRIS_CC0_REGNUM
));
3416 RTX_FRAME_RELATED_P (mov
) = 1;
3417 RTX_FRAME_RELATED_P (RTVEC_ELT (vec
, 1)) = 1;
3422 vec
= rtvec_alloc (nregs
+ (increment
!= 0 ? 1 : 0));
3424 = gen_rtx_SET (replace_equiv_address (dest
,
3425 plus_constant (Pmode
, destreg
,
3427 gen_rtx_REG (SImode
, regno
));
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
3434 RTX_FRAME_RELATED_P (RTVEC_ELT (vec
, 0)) = 1;
3439 = gen_rtx_SET (destreg
, plus_constant (Pmode
, destreg
,
3441 ? increment
: nregs
* 4));
3445 RTX_FRAME_RELATED_P (RTVEC_ELT (vec
, 1)) = 1;
3447 /* Don't call adjust_address_nv on a post-incremented address if
3449 if (GET_CODE (XEXP (dest
, 0)) == POST_INC
)
3450 dest
= replace_equiv_address (dest
, destreg
);
3453 for (i
= 1; i
< nregs
; i
++, eltno
++)
3455 RTVEC_ELT (vec
, eltno
)
3456 = gen_rtx_SET (adjust_address_nv (dest
, SImode
, i
* 4),
3457 gen_rtx_REG (SImode
, regno
));
3459 RTX_FRAME_RELATED_P (RTVEC_ELT (vec
, eltno
)) = 1;
3464 insn
= emit_insn (gen_rtx_PARALLEL (VOIDmode
, vec
));
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
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
++)
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
);
3488 RTX_FRAME_RELATED_P (insn
) = 1;
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
3501 cris_order_for_addsi3 (rtx
*operands
, int n
)
3503 if (!REG_P (operands
[n
]))
3505 rtx tem
= operands
[n
];
3506 operands
[n
] = operands
[n
+ 1];
3507 operands
[n
+ 1] = tem
;
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
3517 cris_output_addr_const (FILE *file
, rtx x
)
3520 output_addr_const (file
, x
);
3524 /* Worker function for ASM_OUTPUT_SYMBOL_REF. */
3527 cris_asm_output_symbol_ref (FILE *file
, rtx x
)
3529 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
3530 assemble_name (file
, XSTR (x
, 0));
3533 /* Worker function for ASM_OUTPUT_LABEL_REF. */
3536 cris_asm_output_label_ref (FILE *file
, char *buf
)
3538 assemble_name (file
, buf
);
3541 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3544 cris_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
3545 int incoming ATTRIBUTE_UNUSED
)
3547 return gen_rtx_REG (Pmode
, CRIS_STRUCT_VALUE_REGNUM
);
3550 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3553 cris_setup_incoming_varargs (cumulative_args_t ca_v
,
3554 const function_arg_info
&,
3555 int *pretend_arg_size
,
3558 CUMULATIVE_ARGS
*ca
= get_cumulative_args (ca_v
);
3560 if (ca
->regs
< CRIS_MAX_ARGS_IN_REGS
)
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;
3568 fprintf (asm_out_file
,
3569 "\n; VA:: ANSI: %d args before, anon @ #%d, %dtime\n",
3570 ca
->regs
, *pretend_arg_size
, second_time
);
3573 /* Return true if ARG must be passed by invisible reference.
3574 For cris, we pass <= 8 bytes by value, others by reference. */
3577 cris_pass_by_reference (cumulative_args_t
, const function_arg_info
&arg
)
3579 return (targetm
.calls
.must_pass_in_stack (arg
)
3580 || CRIS_FUNCTION_ARG_SIZE (arg
.mode
, arg
.type
) > 8);
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. */
3588 cris_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
3590 int *punsignedp ATTRIBUTE_UNUSED
,
3591 const_tree fntype ATTRIBUTE_UNUSED
,
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)
3599 return CRIS_PROMOTED_MODE (mode
, *punsignedp
, type
);
3602 /* Atomic types require alignment to be at least their "natural" size. */
3605 cris_atomic_align_for_mode (machine_mode mode
)
3607 return GET_MODE_BITSIZE (mode
);
3610 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
3614 cris_function_value(const_tree type
,
3615 const_tree func ATTRIBUTE_UNUSED
,
3616 bool outgoing ATTRIBUTE_UNUSED
)
3618 return gen_rtx_REG (TYPE_MODE (type
), CRIS_FIRST_ARG_REG
);
3621 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
3625 cris_libcall_value (machine_mode mode
,
3626 const_rtx fun ATTRIBUTE_UNUSED
)
3628 return gen_rtx_REG (mode
, CRIS_FIRST_ARG_REG
);
3631 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
3635 cris_function_value_regno_p (const unsigned int regno
)
3637 return (regno
== CRIS_FIRST_ARG_REG
);
3641 cris_arg_partial_bytes (cumulative_args_t ca
, const function_arg_info
&arg
)
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
;
3653 cris_function_arg_1 (cumulative_args_t ca_v
, const function_arg_info
&arg
,
3656 const CUMULATIVE_ARGS
*ca
= get_cumulative_args (ca_v
);
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
);
3664 /* Worker function for TARGET_FUNCTION_ARG.
3665 The void_type_node is sent as a "closing" call. */
3668 cris_function_arg (cumulative_args_t ca
, const function_arg_info
&arg
)
3670 return cris_function_arg_1 (ca
, arg
, false);
3673 /* Worker function for TARGET_FUNCTION_INCOMING_ARG.
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. */
3681 cris_function_incoming_arg (cumulative_args_t ca
, const function_arg_info
&arg
)
3683 return cris_function_arg_1 (ca
, arg
, true);
3686 /* Worker function for TARGET_FUNCTION_ARG_ADVANCE. */
3689 cris_function_arg_advance (cumulative_args_t ca_v
,
3690 const function_arg_info
&arg
)
3692 CUMULATIVE_ARGS
*ca
= get_cumulative_args (ca_v
);
3694 ca
->regs
+= (3 + CRIS_FUNCTION_ARG_SIZE (arg
.mode
, arg
.type
)) / 4;
3697 /* Worker function for TARGET_MD_ASM_ADJUST. */
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*/)
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
);
3712 /* Determine if the source using MOF. If it is, automatically
3713 clobbering MOF would cause it to have impossible constraints. */
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
)
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
]))
3725 for (unsigned i
= 0, n
= inputs
.length(); i
< n
; ++i
)
3726 if (reg_overlap_mentioned_p (mof_reg
, inputs
[i
]))
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
);
3736 /* Implement TARGET_FRAME_POINTER_REQUIRED.
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. */
3743 cris_frame_pointer_required (void)
3745 return !crtl
->sp_is_unchanging
;
3748 /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
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. */
3762 cris_asm_trampoline_template (FILE *f
)
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");
3772 /* Implement TARGET_TRAMPOLINE_INIT. */
3775 cris_trampoline_init (rtx m_tramp
, tree fndecl
, rtx chain_value
)
3777 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
3780 emit_block_move (m_tramp
, assemble_trampoline_template (),
3781 GEN_INT (TRAMPOLINE_SIZE
), BLOCK_OP_NORMAL
);
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
);
3788 /* Note that there is no need to do anything with the cache for
3789 sake of a trampoline. */
3792 /* Implement TARGET_HARD_REGNO_NREGS.
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. */
3798 cris_hard_regno_nregs (unsigned int, machine_mode mode
)
3800 if (mode
== VOIDmode
)
3802 return CEIL (GET_MODE_SIZE (mode
), UNITS_PER_WORD
);
3805 /* Implement TARGET_HARD_REGNO_MODE_OK.
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. */
3811 cris_hard_regno_mode_ok (unsigned int regno
, machine_mode mode
)
3813 return ((mode
== CCmode
|| regno
!= CRIS_CC0_REGNUM
)
3814 && (GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
3815 || regno
!= CRIS_MOF_REGNUM
));
3818 /* Return the preferred minimum alignment for a static object. */
3820 static HOST_WIDE_INT
3821 cris_preferred_minimum_alignment (void)
3823 if (!TARGET_CONST_ALIGN
)
3825 if (TARGET_ALIGN_BY_32
)
3830 /* Implement TARGET_STATIC_RTX_ALIGNMENT. */
3832 static HOST_WIDE_INT
3833 cris_static_rtx_alignment (machine_mode mode
)
3835 return MAX (cris_preferred_minimum_alignment (), GET_MODE_ALIGNMENT (mode
));
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. */
3845 static HOST_WIDE_INT
3846 cris_constant_alignment (const_tree
, HOST_WIDE_INT basic_align
)
3848 return MAX (cris_preferred_minimum_alignment (), basic_align
);
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. */
3856 enum rtx_code
Get_code (rtx
);
3861 return GET_CODE (x
);
3864 const char *Get_mode (rtx
);
3869 return GET_MODE_NAME (GET_MODE (x
));
3872 rtx
Xexp (rtx
, int);
3880 rtx
Xvecexp (rtx
, int, int);
3883 Xvecexp (rtx x
, int n
, int m
)
3885 return XVECEXP (x
, n
, m
);
3888 int Get_rtx_len (rtx
);
3893 return GET_RTX_LENGTH (GET_CODE (x
));
3896 /* Use upper-case to distinguish from local variables that are sometimes
3897 called next_insn and prev_insn. */
3899 rtx
Next_insn (rtx
);
3902 Next_insn (rtx insn
)
3904 return NEXT_INSN (insn
);
3907 rtx
Prev_insn (rtx
);
3910 Prev_insn (rtx insn
)
3912 return PREV_INSN (insn
);
3916 #include "gt-cris.h"
3920 * eval: (c-set-style "gnu")
3921 * indent-tabs-mode: t