* config/cris/cris.c (cris_preferred_reload_class): New function.
[official-gcc.git] / gcc / config / cris / cris.c
blob35ecaa8e2fd6b050ce1fec5e6532cc588c1cc9d3
1 /* Definitions for GCC. Part of the machine description for CRIS.
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 Contributed by Axis Communications. Written by Hans-Peter Nilsson.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "regs.h"
28 #include "hard-reg-set.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "insn-attr.h"
32 #include "flags.h"
33 #include "tree.h"
34 #include "expr.h"
35 #include "except.h"
36 #include "function.h"
37 #include "diagnostic-core.h"
38 #include "recog.h"
39 #include "reload.h"
40 #include "tm_p.h"
41 #include "debug.h"
42 #include "output.h"
43 #include "target.h"
44 #include "target-def.h"
45 #include "ggc.h"
46 #include "optabs.h"
47 #include "df.h"
48 #include "opts.h"
50 /* Usable when we have an amount to add or subtract, and want the
51 optimal size of the insn. */
52 #define ADDITIVE_SIZE_MODIFIER(size) \
53 ((size) <= 63 ? "q" : (size) <= 255 ? "u.b" : (size) <= 65535 ? "u.w" : ".d")
55 #define LOSE_AND_RETURN(msgid, x) \
56 do \
57 { \
58 cris_operand_lossage (msgid, x); \
59 return; \
60 } while (0)
62 enum cris_retinsn_type
63 { CRIS_RETINSN_UNKNOWN = 0, CRIS_RETINSN_RET, CRIS_RETINSN_JUMP };
65 /* Per-function machine data. */
66 struct GTY(()) machine_function
68 int needs_return_address_on_stack;
70 /* This is the number of registers we save in the prologue due to
71 stdarg. */
72 int stdarg_regs;
74 enum cris_retinsn_type return_type;
77 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
78 pattern. */
79 static char cris_output_insn_is_bound = 0;
81 /* In code for output macros, this is how we know whether e.g. constant
82 goes in code or in a static initializer. */
83 static int in_code = 0;
85 /* Fix for reg_overlap_mentioned_p. */
86 static int cris_reg_overlap_mentioned_p (rtx, rtx);
88 static enum machine_mode cris_promote_function_mode (const_tree, enum machine_mode,
89 int *, const_tree, int);
91 static void cris_print_base (rtx, FILE *);
93 static void cris_print_index (rtx, FILE *);
95 static void cris_output_addr_const (FILE *, rtx);
97 static struct machine_function * cris_init_machine_status (void);
99 static rtx cris_struct_value_rtx (tree, int);
101 static void cris_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
102 tree type, int *, int);
104 static int cris_initial_frame_pointer_offset (void);
106 static void cris_operand_lossage (const char *, rtx);
108 static int cris_reg_saved_in_regsave_area (unsigned int, bool);
110 static void cris_print_operand (FILE *, rtx, int);
112 static void cris_print_operand_address (FILE *, rtx);
114 static bool cris_print_operand_punct_valid_p (unsigned char code);
116 static bool cris_output_addr_const_extra (FILE *, rtx);
118 static void cris_conditional_register_usage (void);
120 static void cris_asm_output_mi_thunk
121 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
123 static void cris_file_start (void);
124 static void cris_init_libfuncs (void);
126 static reg_class_t cris_preferred_reload_class (rtx, reg_class_t);
128 static int cris_register_move_cost (enum machine_mode, reg_class_t, reg_class_t);
129 static int cris_memory_move_cost (enum machine_mode, reg_class_t, bool);
130 static bool cris_rtx_costs (rtx, int, int, int, int *, bool);
131 static int cris_address_cost (rtx, bool);
132 static bool cris_pass_by_reference (cumulative_args_t, enum machine_mode,
133 const_tree, bool);
134 static int cris_arg_partial_bytes (cumulative_args_t, enum machine_mode,
135 tree, bool);
136 static rtx cris_function_arg (cumulative_args_t, enum machine_mode,
137 const_tree, bool);
138 static rtx cris_function_incoming_arg (cumulative_args_t,
139 enum machine_mode, const_tree, bool);
140 static void cris_function_arg_advance (cumulative_args_t, enum machine_mode,
141 const_tree, bool);
142 static tree cris_md_asm_clobbers (tree, tree, tree);
144 static void cris_option_override (void);
146 static bool cris_frame_pointer_required (void);
148 static void cris_asm_trampoline_template (FILE *);
149 static void cris_trampoline_init (rtx, tree, rtx);
151 static rtx cris_function_value(const_tree, const_tree, bool);
152 static rtx cris_libcall_value (enum machine_mode, const_rtx);
154 /* This is the parsed result of the "-max-stack-stackframe=" option. If
155 it (still) is zero, then there was no such option given. */
156 int cris_max_stackframe = 0;
158 /* This is the parsed result of the "-march=" option, if given. */
159 int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
161 #undef TARGET_ASM_ALIGNED_HI_OP
162 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
163 #undef TARGET_ASM_ALIGNED_SI_OP
164 #define TARGET_ASM_ALIGNED_SI_OP "\t.dword\t"
165 #undef TARGET_ASM_ALIGNED_DI_OP
166 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
168 /* We need to define these, since the 2byte, 4byte, 8byte op:s are only
169 available in ELF. These "normal" pseudos do not have any alignment
170 constraints or side-effects. */
171 #undef TARGET_ASM_UNALIGNED_HI_OP
172 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
174 #undef TARGET_ASM_UNALIGNED_SI_OP
175 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
177 #undef TARGET_ASM_UNALIGNED_DI_OP
178 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
180 #undef TARGET_PRINT_OPERAND
181 #define TARGET_PRINT_OPERAND cris_print_operand
182 #undef TARGET_PRINT_OPERAND_ADDRESS
183 #define TARGET_PRINT_OPERAND_ADDRESS cris_print_operand_address
184 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
185 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P cris_print_operand_punct_valid_p
186 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
187 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA cris_output_addr_const_extra
189 #undef TARGET_CONDITIONAL_REGISTER_USAGE
190 #define TARGET_CONDITIONAL_REGISTER_USAGE cris_conditional_register_usage
192 #undef TARGET_ASM_OUTPUT_MI_THUNK
193 #define TARGET_ASM_OUTPUT_MI_THUNK cris_asm_output_mi_thunk
194 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
195 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
197 #undef TARGET_ASM_FILE_START
198 #define TARGET_ASM_FILE_START cris_file_start
200 #undef TARGET_INIT_LIBFUNCS
201 #define TARGET_INIT_LIBFUNCS cris_init_libfuncs
203 #undef TARGET_PREFERRED_RELOAD_CLASS
204 #define TARGET_PREFERRED_RELOAD_CLASS cris_preferred_reload_class
206 #undef TARGET_REGISTER_MOVE_COST
207 #define TARGET_REGISTER_MOVE_COST cris_register_move_cost
208 #undef TARGET_MEMORY_MOVE_COST
209 #define TARGET_MEMORY_MOVE_COST cris_memory_move_cost
210 #undef TARGET_RTX_COSTS
211 #define TARGET_RTX_COSTS cris_rtx_costs
212 #undef TARGET_ADDRESS_COST
213 #define TARGET_ADDRESS_COST cris_address_cost
215 #undef TARGET_PROMOTE_FUNCTION_MODE
216 #define TARGET_PROMOTE_FUNCTION_MODE cris_promote_function_mode
218 #undef TARGET_STRUCT_VALUE_RTX
219 #define TARGET_STRUCT_VALUE_RTX cris_struct_value_rtx
220 #undef TARGET_SETUP_INCOMING_VARARGS
221 #define TARGET_SETUP_INCOMING_VARARGS cris_setup_incoming_varargs
222 #undef TARGET_PASS_BY_REFERENCE
223 #define TARGET_PASS_BY_REFERENCE cris_pass_by_reference
224 #undef TARGET_ARG_PARTIAL_BYTES
225 #define TARGET_ARG_PARTIAL_BYTES cris_arg_partial_bytes
226 #undef TARGET_FUNCTION_ARG
227 #define TARGET_FUNCTION_ARG cris_function_arg
228 #undef TARGET_FUNCTION_INCOMING_ARG
229 #define TARGET_FUNCTION_INCOMING_ARG cris_function_incoming_arg
230 #undef TARGET_FUNCTION_ARG_ADVANCE
231 #define TARGET_FUNCTION_ARG_ADVANCE cris_function_arg_advance
232 #undef TARGET_MD_ASM_CLOBBERS
233 #define TARGET_MD_ASM_CLOBBERS cris_md_asm_clobbers
234 #undef TARGET_FRAME_POINTER_REQUIRED
235 #define TARGET_FRAME_POINTER_REQUIRED cris_frame_pointer_required
237 #undef TARGET_OPTION_OVERRIDE
238 #define TARGET_OPTION_OVERRIDE cris_option_override
240 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
241 #define TARGET_ASM_TRAMPOLINE_TEMPLATE cris_asm_trampoline_template
242 #undef TARGET_TRAMPOLINE_INIT
243 #define TARGET_TRAMPOLINE_INIT cris_trampoline_init
245 #undef TARGET_FUNCTION_VALUE
246 #define TARGET_FUNCTION_VALUE cris_function_value
247 #undef TARGET_LIBCALL_VALUE
248 #define TARGET_LIBCALL_VALUE cris_libcall_value
250 struct gcc_target targetm = TARGET_INITIALIZER;
252 /* Helper for cris_load_multiple_op and cris_ret_movem_op. */
254 bool
255 cris_movem_load_rest_p (rtx op, int offs)
257 unsigned int reg_count = XVECLEN (op, 0) - offs;
258 rtx src_addr;
259 int i;
260 rtx elt;
261 int setno;
262 int regno_dir = 1;
263 unsigned int regno = 0;
265 /* Perform a quick check so we don't blow up below. FIXME: Adjust for
266 other than (MEM reg). */
267 if (reg_count <= 1
268 || GET_CODE (XVECEXP (op, 0, offs)) != SET
269 || !REG_P (SET_DEST (XVECEXP (op, 0, offs)))
270 || !MEM_P (SET_SRC (XVECEXP (op, 0, offs))))
271 return false;
273 /* Check a possible post-inc indicator. */
274 if (GET_CODE (SET_SRC (XVECEXP (op, 0, offs + 1))) == PLUS)
276 rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, offs + 1)), 0);
277 rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, offs + 1)), 1);
279 reg_count--;
281 if (reg_count == 1
282 || !REG_P (reg)
283 || !REG_P (SET_DEST (XVECEXP (op, 0, offs + 1)))
284 || REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, offs + 1)))
285 || !CONST_INT_P (inc)
286 || INTVAL (inc) != (HOST_WIDE_INT) reg_count * 4)
287 return false;
288 i = offs + 2;
290 else
291 i = offs + 1;
293 if (!TARGET_V32)
295 regno_dir = -1;
296 regno = reg_count - 1;
299 elt = XVECEXP (op, 0, offs);
300 src_addr = XEXP (SET_SRC (elt), 0);
302 if (GET_CODE (elt) != SET
303 || !REG_P (SET_DEST (elt))
304 || GET_MODE (SET_DEST (elt)) != SImode
305 || REGNO (SET_DEST (elt)) != regno
306 || !MEM_P (SET_SRC (elt))
307 || GET_MODE (SET_SRC (elt)) != SImode
308 || !memory_address_p (SImode, src_addr))
309 return false;
311 for (setno = 1; i < XVECLEN (op, 0); setno++, i++)
313 rtx elt = XVECEXP (op, 0, i);
314 regno += regno_dir;
316 if (GET_CODE (elt) != SET
317 || !REG_P (SET_DEST (elt))
318 || GET_MODE (SET_DEST (elt)) != SImode
319 || REGNO (SET_DEST (elt)) != regno
320 || !MEM_P (SET_SRC (elt))
321 || GET_MODE (SET_SRC (elt)) != SImode
322 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
323 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
324 || !CONST_INT_P (XEXP (XEXP (SET_SRC (elt), 0), 1))
325 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != setno * 4)
326 return false;
329 return true;
332 /* Worker function for predicate for the parallel contents in a movem
333 to-memory. */
335 bool
336 cris_store_multiple_op_p (rtx op)
338 int reg_count = XVECLEN (op, 0);
339 rtx dest;
340 rtx dest_addr;
341 rtx dest_base;
342 int i;
343 rtx elt;
344 int setno;
345 int regno_dir = 1;
346 int regno = 0;
347 int offset = 0;
349 /* Perform a quick check so we don't blow up below. FIXME: Adjust for
350 other than (MEM reg) and (MEM (PLUS reg const)). */
351 if (reg_count <= 1)
352 return false;
354 elt = XVECEXP (op, 0, 0);
356 if (GET_CODE (elt) != SET)
357 return false;
359 dest = SET_DEST (elt);
361 if (!REG_P (SET_SRC (elt)) || !MEM_P (dest))
362 return false;
364 dest_addr = XEXP (dest, 0);
366 /* Check a possible post-inc indicator. */
367 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS)
369 rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 0);
370 rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1);
372 reg_count--;
374 if (reg_count == 1
375 || !REG_P (reg)
376 || !REG_P (SET_DEST (XVECEXP (op, 0, 1)))
377 || REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, 1)))
378 || !CONST_INT_P (inc)
379 /* Support increment by number of registers, and by the offset
380 of the destination, if it has the form (MEM (PLUS reg
381 offset)). */
382 || !((REG_P (dest_addr)
383 && REGNO (dest_addr) == REGNO (reg)
384 && INTVAL (inc) == (HOST_WIDE_INT) reg_count * 4)
385 || (GET_CODE (dest_addr) == PLUS
386 && REG_P (XEXP (dest_addr, 0))
387 && REGNO (XEXP (dest_addr, 0)) == REGNO (reg)
388 && CONST_INT_P (XEXP (dest_addr, 1))
389 && INTVAL (XEXP (dest_addr, 1)) == INTVAL (inc))))
390 return false;
392 i = 2;
394 else
395 i = 1;
397 if (!TARGET_V32)
399 regno_dir = -1;
400 regno = reg_count - 1;
403 if (GET_CODE (elt) != SET
404 || !REG_P (SET_SRC (elt))
405 || GET_MODE (SET_SRC (elt)) != SImode
406 || REGNO (SET_SRC (elt)) != (unsigned int) regno
407 || !MEM_P (SET_DEST (elt))
408 || GET_MODE (SET_DEST (elt)) != SImode)
409 return false;
411 if (REG_P (dest_addr))
413 dest_base = dest_addr;
414 offset = 0;
416 else if (GET_CODE (dest_addr) == PLUS
417 && REG_P (XEXP (dest_addr, 0))
418 && CONST_INT_P (XEXP (dest_addr, 1)))
420 dest_base = XEXP (dest_addr, 0);
421 offset = INTVAL (XEXP (dest_addr, 1));
423 else
424 return false;
426 for (setno = 1; i < XVECLEN (op, 0); setno++, i++)
428 rtx elt = XVECEXP (op, 0, i);
429 regno += regno_dir;
431 if (GET_CODE (elt) != SET
432 || !REG_P (SET_SRC (elt))
433 || GET_MODE (SET_SRC (elt)) != SImode
434 || REGNO (SET_SRC (elt)) != (unsigned int) regno
435 || !MEM_P (SET_DEST (elt))
436 || GET_MODE (SET_DEST (elt)) != SImode
437 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
438 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_base)
439 || !CONST_INT_P (XEXP (XEXP (SET_DEST (elt), 0), 1))
440 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != setno * 4 + offset)
441 return false;
444 return true;
447 /* The TARGET_CONDITIONAL_REGISTER_USAGE worker. */
449 static void
450 cris_conditional_register_usage (void)
452 /* FIXME: This isn't nice. We should be able to use that register for
453 something else if the PIC table isn't needed. */
454 if (flag_pic)
455 fixed_regs[PIC_OFFSET_TABLE_REGNUM]
456 = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
458 /* Allow use of ACR (PC in pre-V32) and tweak order. */
459 if (TARGET_V32)
461 static const int reg_alloc_order_v32[] = REG_ALLOC_ORDER_V32;
462 unsigned int i;
464 fixed_regs[CRIS_ACR_REGNUM] = 0;
466 for (i = 0;
467 i < sizeof (reg_alloc_order_v32)/sizeof (reg_alloc_order_v32[0]);
468 i++)
469 reg_alloc_order[i] = reg_alloc_order_v32[i];
472 if (TARGET_HAS_MUL_INSNS)
473 fixed_regs[CRIS_MOF_REGNUM] = 0;
475 /* On early versions, we must use the 16-bit condition-code register,
476 which has another name. */
477 if (cris_cpu_version < 8)
478 reg_names[CRIS_CC0_REGNUM] = "ccr";
481 /* Return crtl->uses_pic_offset_table. For use in cris.md,
482 since some generated files do not include function.h. */
485 cris_cfun_uses_pic_table (void)
487 return crtl->uses_pic_offset_table;
490 /* Given an rtx, return the text string corresponding to the CODE of X.
491 Intended for use in the assembly language output section of a
492 define_insn. */
494 const char *
495 cris_op_str (rtx x)
497 cris_output_insn_is_bound = 0;
498 switch (GET_CODE (x))
500 case PLUS:
501 return "add";
502 break;
504 case MINUS:
505 return "sub";
506 break;
508 case MULT:
509 /* This function is for retrieving a part of an instruction name for
510 an operator, for immediate output. If that ever happens for
511 MULT, we need to apply TARGET_MUL_BUG in the caller. Make sure
512 we notice. */
513 internal_error ("MULT case in cris_op_str");
514 break;
516 case DIV:
517 return "div";
518 break;
520 case AND:
521 return "and";
522 break;
524 case IOR:
525 return "or";
526 break;
528 case XOR:
529 return "xor";
530 break;
532 case NOT:
533 return "not";
534 break;
536 case ASHIFT:
537 return "lsl";
538 break;
540 case LSHIFTRT:
541 return "lsr";
542 break;
544 case ASHIFTRT:
545 return "asr";
546 break;
548 case UMIN:
549 /* Used to control the sign/zero-extend character for the 'E' modifier.
550 BOUND has none. */
551 cris_output_insn_is_bound = 1;
552 return "bound";
553 break;
555 default:
556 return "Unknown operator";
557 break;
561 /* Emit an error message when we're in an asm, and a fatal error for
562 "normal" insns. Formatted output isn't easily implemented, since we
563 use output_operand_lossage to output the actual message and handle the
564 categorization of the error. */
566 static void
567 cris_operand_lossage (const char *msgid, rtx op)
569 debug_rtx (op);
570 output_operand_lossage ("%s", msgid);
573 /* Print an index part of an address to file. */
575 static void
576 cris_print_index (rtx index, FILE *file)
578 /* Make the index "additive" unless we'll output a negative number, in
579 which case the sign character is free (as in free beer). */
580 if (!CONST_INT_P (index) || INTVAL (index) >= 0)
581 putc ('+', file);
583 if (REG_P (index))
584 fprintf (file, "$%s.b", reg_names[REGNO (index)]);
585 else if (CONSTANT_P (index))
586 cris_output_addr_const (file, index);
587 else if (GET_CODE (index) == MULT)
589 fprintf (file, "$%s.",
590 reg_names[REGNO (XEXP (index, 0))]);
592 putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file);
594 else if (GET_CODE (index) == SIGN_EXTEND && MEM_P (XEXP (index, 0)))
596 rtx inner = XEXP (index, 0);
597 rtx inner_inner = XEXP (inner, 0);
599 if (GET_CODE (inner_inner) == POST_INC)
601 fprintf (file, "[$%s+].",
602 reg_names[REGNO (XEXP (inner_inner, 0))]);
603 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
605 else
607 fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]);
609 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
612 else if (MEM_P (index))
614 rtx inner = XEXP (index, 0);
615 if (GET_CODE (inner) == POST_INC)
616 fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]);
617 else
618 fprintf (file, "[$%s].d", reg_names[REGNO (inner)]);
620 else
621 cris_operand_lossage ("unexpected index-type in cris_print_index",
622 index);
625 /* Print a base rtx of an address to file. */
627 static void
628 cris_print_base (rtx base, FILE *file)
630 if (REG_P (base))
631 fprintf (file, "$%s", reg_names[REGNO (base)]);
632 else if (GET_CODE (base) == POST_INC)
634 gcc_assert (REGNO (XEXP (base, 0)) != CRIS_ACR_REGNUM);
635 fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]);
637 else
638 cris_operand_lossage ("unexpected base-type in cris_print_base",
639 base);
642 /* Usable as a guard in expressions. */
645 cris_fatal (char *arg)
647 internal_error (arg);
649 /* We'll never get here; this is just to appease compilers. */
650 return 0;
653 /* Return nonzero if REGNO is an ordinary register that *needs* to be
654 saved together with other registers, possibly by a MOVEM instruction,
655 or is saved for target-independent reasons. There may be
656 target-dependent reasons to save the register anyway; this is just a
657 wrapper for a complicated conditional. */
659 static int
660 cris_reg_saved_in_regsave_area (unsigned int regno, bool got_really_used)
662 return
663 (((df_regs_ever_live_p (regno)
664 && !call_used_regs[regno])
665 || (regno == PIC_OFFSET_TABLE_REGNUM
666 && (got_really_used
667 /* It is saved anyway, if there would be a gap. */
668 || (flag_pic
669 && df_regs_ever_live_p (regno + 1)
670 && !call_used_regs[regno + 1]))))
671 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
672 && regno != CRIS_SRP_REGNUM)
673 || (crtl->calls_eh_return
674 && (regno == EH_RETURN_DATA_REGNO (0)
675 || regno == EH_RETURN_DATA_REGNO (1)
676 || regno == EH_RETURN_DATA_REGNO (2)
677 || regno == EH_RETURN_DATA_REGNO (3)));
680 /* The PRINT_OPERAND worker. */
682 static void
683 cris_print_operand (FILE *file, rtx x, int code)
685 rtx operand = x;
687 /* Size-strings corresponding to MULT expressions. */
688 static const char *const mults[] = { "BAD:0", ".b", ".w", "BAD:3", ".d" };
690 /* New code entries should just be added to the switch below. If
691 handling is finished, just return. If handling was just a
692 modification of the operand, the modified operand should be put in
693 "operand", and then do a break to let default handling
694 (zero-modifier) output the operand. */
696 switch (code)
698 case 'b':
699 /* Print the unsigned supplied integer as if it were signed
700 and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc. */
701 if (!CONST_INT_P (x)
702 || !CRIS_CONST_OK_FOR_LETTER_P (INTVAL (x), 'O'))
703 LOSE_AND_RETURN ("invalid operand for 'b' modifier", x);
704 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
705 INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535));
706 return;
708 case 'x':
709 /* Print assembler code for operator. */
710 fprintf (file, "%s", cris_op_str (operand));
711 return;
713 case 'o':
715 /* A movem modifier working on a parallel; output the register
716 name. */
717 int regno;
719 if (GET_CODE (x) != PARALLEL)
720 LOSE_AND_RETURN ("invalid operand for 'o' modifier", x);
722 /* The second item can be (set reg (plus reg const)) to denote a
723 postincrement. */
724 regno
725 = (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS
726 ? XVECLEN (x, 0) - 2
727 : XVECLEN (x, 0) - 1);
729 fprintf (file, "$%s", reg_names [regno]);
731 return;
733 case 'O':
735 /* A similar movem modifier; output the memory operand. */
736 rtx addr;
738 if (GET_CODE (x) != PARALLEL)
739 LOSE_AND_RETURN ("invalid operand for 'O' modifier", x);
741 /* The lowest mem operand is in the first item, but perhaps it
742 needs to be output as postincremented. */
743 addr = MEM_P (SET_SRC (XVECEXP (x, 0, 0)))
744 ? XEXP (SET_SRC (XVECEXP (x, 0, 0)), 0)
745 : XEXP (SET_DEST (XVECEXP (x, 0, 0)), 0);
747 /* The second item can be a (set reg (plus reg const)) to denote
748 a modification. */
749 if (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS)
751 /* It's a post-increment, if the address is a naked (reg). */
752 if (REG_P (addr))
753 addr = gen_rtx_POST_INC (SImode, addr);
754 else
756 /* Otherwise, it's a side-effect; RN=RN+M. */
757 fprintf (file, "[$%s=$%s%s%d]",
758 reg_names [REGNO (SET_DEST (XVECEXP (x, 0, 1)))],
759 reg_names [REGNO (XEXP (addr, 0))],
760 INTVAL (XEXP (addr, 1)) < 0 ? "" : "+",
761 (int) INTVAL (XEXP (addr, 1)));
762 return;
765 output_address (addr);
767 return;
769 case 'p':
770 /* Adjust a power of two to its log2. */
771 if (!CONST_INT_P (x) || exact_log2 (INTVAL (x)) < 0 )
772 LOSE_AND_RETURN ("invalid operand for 'p' modifier", x);
773 fprintf (file, "%d", exact_log2 (INTVAL (x)));
774 return;
776 case 's':
777 /* For an integer, print 'b' or 'w' if <= 255 or <= 65535
778 respectively. This modifier also terminates the inhibiting
779 effects of the 'x' modifier. */
780 cris_output_insn_is_bound = 0;
781 if (GET_MODE (x) == VOIDmode && CONST_INT_P (x))
783 if (INTVAL (x) >= 0)
785 if (INTVAL (x) <= 255)
786 putc ('b', file);
787 else if (INTVAL (x) <= 65535)
788 putc ('w', file);
789 else
790 putc ('d', file);
792 else
793 putc ('d', file);
794 return;
797 /* For a non-integer, print the size of the operand. */
798 putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode)
799 ? 'd' : GET_MODE (x) == HImode ? 'w'
800 : GET_MODE (x) == QImode ? 'b'
801 /* If none of the above, emit an erroneous size letter. */
802 : 'X',
803 file);
804 return;
806 case 'z':
807 /* Const_int: print b for -127 <= x <= 255,
808 w for -32768 <= x <= 65535, else die. */
809 if (!CONST_INT_P (x)
810 || INTVAL (x) < -32768 || INTVAL (x) > 65535)
811 LOSE_AND_RETURN ("invalid operand for 'z' modifier", x);
812 putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file);
813 return;
815 case 'Z':
816 /* If this is a GOT-symbol, print the size-letter corresponding to
817 -fpic/-fPIC. For everything else, print "d". */
818 putc ((flag_pic == 1
819 && GET_CODE (x) == CONST
820 && GET_CODE (XEXP (x, 0)) == UNSPEC
821 && XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREAD)
822 ? 'w' : 'd', file);
823 return;
825 case '#':
826 /* Output a 'nop' if there's nothing for the delay slot.
827 This method stolen from the sparc files. */
828 if (dbr_sequence_length () == 0)
829 fputs ("\n\tnop", file);
830 return;
832 case '!':
833 /* Output directive for alignment padded with "nop" insns.
834 Optimizing for size, it's plain 4-byte alignment, otherwise we
835 align the section to a cache-line (32 bytes) and skip at max 2
836 bytes, i.e. we skip if it's the last insn on a cache-line. The
837 latter is faster by a small amount (for two test-programs 99.6%
838 and 99.9%) and larger by a small amount (ditto 100.1% and
839 100.2%). This is supposed to be the simplest yet performance-
840 wise least intrusive way to make sure the immediately following
841 (supposed) muls/mulu insn isn't located at the end of a
842 cache-line. */
843 if (TARGET_MUL_BUG)
844 fputs (optimize_size
845 ? ".p2alignw 2,0x050f\n\t"
846 : ".p2alignw 5,0x050f,2\n\t", file);
847 return;
849 case ':':
850 /* The PIC register. */
851 if (! flag_pic)
852 internal_error ("invalid use of ':' modifier");
853 fprintf (file, "$%s", reg_names [PIC_OFFSET_TABLE_REGNUM]);
854 return;
856 case 'H':
857 /* Print high (most significant) part of something. */
858 switch (GET_CODE (operand))
860 case CONST_INT:
861 /* If we're having 64-bit HOST_WIDE_INTs, the whole (DImode)
862 value is kept here, and so may be other than 0 or -1. */
863 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
864 INTVAL (operand_subword (operand, 1, 0, DImode)));
865 return;
867 case CONST_DOUBLE:
868 /* High part of a long long constant. */
869 if (GET_MODE (operand) == VOIDmode)
871 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_HIGH (x));
872 return;
874 else
875 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
877 case REG:
878 /* Print reg + 1. Check that there's not an attempt to print
879 high-parts of registers like stack-pointer or higher, except
880 for SRP (where the "high part" is MOF). */
881 if (REGNO (operand) > STACK_POINTER_REGNUM - 2
882 && (REGNO (operand) != CRIS_SRP_REGNUM
883 || CRIS_SRP_REGNUM + 1 != CRIS_MOF_REGNUM
884 || fixed_regs[CRIS_MOF_REGNUM] != 0))
885 LOSE_AND_RETURN ("bad register", operand);
886 fprintf (file, "$%s", reg_names[REGNO (operand) + 1]);
887 return;
889 case MEM:
890 /* Adjust memory address to high part. */
892 rtx adj_mem = operand;
893 int size
894 = GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT;
896 /* Adjust so we can use two SImode in DImode.
897 Calling adj_offsettable_operand will make sure it is an
898 offsettable address. Don't do this for a postincrement
899 though; it should remain as it was. */
900 if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC)
901 adj_mem
902 = adjust_address (adj_mem, GET_MODE (adj_mem), size / 2);
904 output_address (XEXP (adj_mem, 0));
905 return;
908 default:
909 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
912 case 'L':
913 /* Strip the MEM expression. */
914 operand = XEXP (operand, 0);
915 break;
917 case 'e':
918 /* Like 'E', but ignore state set by 'x'. FIXME: Use code
919 iterators and attributes in cris.md to avoid the need for %x
920 and %E (and %e) and state passed between those modifiers. */
921 cris_output_insn_is_bound = 0;
922 /* FALL THROUGH. */
923 case 'E':
924 /* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless
925 cris_output_insn_is_bound is nonzero. */
926 if (GET_CODE (operand) != SIGN_EXTEND
927 && GET_CODE (operand) != ZERO_EXTEND
928 && !CONST_INT_P (operand))
929 LOSE_AND_RETURN ("invalid operand for 'e' modifier", x);
931 if (cris_output_insn_is_bound)
933 cris_output_insn_is_bound = 0;
934 return;
937 putc (GET_CODE (operand) == SIGN_EXTEND
938 || (CONST_INT_P (operand) && INTVAL (operand) < 0)
939 ? 's' : 'u', file);
940 return;
942 case 'm':
943 /* Print the size letter of the inner element. We can do it by
944 calling ourselves with the 's' modifier. */
945 if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND)
946 LOSE_AND_RETURN ("invalid operand for 'm' modifier", x);
947 cris_print_operand (file, XEXP (operand, 0), 's');
948 return;
950 case 'M':
951 /* Print the least significant part of operand. */
952 if (GET_CODE (operand) == CONST_DOUBLE)
954 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
955 return;
957 else if (HOST_BITS_PER_WIDE_INT > 32 && CONST_INT_P (operand))
959 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
960 INTVAL (x) & ((unsigned int) 0x7fffffff * 2 + 1));
961 return;
963 /* Otherwise the least significant part equals the normal part,
964 so handle it normally. */
965 break;
967 case 'A':
968 /* When emitting an add for the high part of a DImode constant, we
969 want to use addq for 0 and adds.w for -1. */
970 if (!CONST_INT_P (operand))
971 LOSE_AND_RETURN ("invalid operand for 'A' modifier", x);
972 fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq");
973 return;
975 case 'd':
976 /* If this is a GOT symbol, force it to be emitted as :GOT and
977 :GOTPLT regardless of -fpic (i.e. not as :GOT16, :GOTPLT16).
978 Avoid making this too much of a special case. */
979 if (flag_pic == 1 && CONSTANT_P (operand))
981 int flag_pic_save = flag_pic;
983 flag_pic = 2;
984 cris_output_addr_const (file, operand);
985 flag_pic = flag_pic_save;
986 return;
988 break;
990 case 'D':
991 /* When emitting an sub for the high part of a DImode constant, we
992 want to use subq for 0 and subs.w for -1. */
993 if (!CONST_INT_P (operand))
994 LOSE_AND_RETURN ("invalid operand for 'D' modifier", x);
995 fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq");
996 return;
998 case 'S':
999 /* Print the operand as the index-part of an address.
1000 Easiest way out is to use cris_print_index. */
1001 cris_print_index (operand, file);
1002 return;
1004 case 'T':
1005 /* Print the size letter for an operand to a MULT, which must be a
1006 const_int with a suitable value. */
1007 if (!CONST_INT_P (operand) || INTVAL (operand) > 4)
1008 LOSE_AND_RETURN ("invalid operand for 'T' modifier", x);
1009 fprintf (file, "%s", mults[INTVAL (operand)]);
1010 return;
1012 case 'u':
1013 /* Print "u.w" if a GOT symbol and flag_pic == 1, else ".d". */
1014 if (flag_pic == 1
1015 && GET_CODE (operand) == CONST
1016 && GET_CODE (XEXP (operand, 0)) == UNSPEC
1017 && XINT (XEXP (operand, 0), 1) == CRIS_UNSPEC_GOTREAD)
1018 fprintf (file, "u.w");
1019 else
1020 fprintf (file, ".d");
1021 return;
1023 case 0:
1024 /* No code, print as usual. */
1025 break;
1027 default:
1028 LOSE_AND_RETURN ("invalid operand modifier letter", x);
1031 /* Print an operand as without a modifier letter. */
1032 switch (GET_CODE (operand))
1034 case REG:
1035 if (REGNO (operand) > 15
1036 && REGNO (operand) != CRIS_MOF_REGNUM
1037 && REGNO (operand) != CRIS_SRP_REGNUM
1038 && REGNO (operand) != CRIS_CC0_REGNUM)
1039 internal_error ("internal error: bad register: %d", REGNO (operand));
1040 fprintf (file, "$%s", reg_names[REGNO (operand)]);
1041 return;
1043 case MEM:
1044 output_address (XEXP (operand, 0));
1045 return;
1047 case CONST_DOUBLE:
1048 if (GET_MODE (operand) == VOIDmode)
1049 /* A long long constant. */
1050 output_addr_const (file, operand);
1051 else
1053 /* Only single precision is allowed as plain operands the
1054 moment. FIXME: REAL_VALUE_FROM_CONST_DOUBLE isn't
1055 documented. */
1056 REAL_VALUE_TYPE r;
1057 long l;
1059 /* FIXME: Perhaps check overflow of the "single". */
1060 REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
1061 REAL_VALUE_TO_TARGET_SINGLE (r, l);
1063 fprintf (file, "0x%lx", l);
1065 return;
1067 case UNSPEC:
1068 /* Fall through. */
1069 case CONST:
1070 cris_output_addr_const (file, operand);
1071 return;
1073 case MULT:
1074 case ASHIFT:
1076 /* For a (MULT (reg X) const_int) we output "rX.S". */
1077 int i = CONST_INT_P (XEXP (operand, 1))
1078 ? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0));
1079 rtx reg = CONST_INT_P (XEXP (operand, 1))
1080 ? XEXP (operand, 0) : XEXP (operand, 1);
1082 if (!REG_P (reg)
1083 || (!CONST_INT_P (XEXP (operand, 0))
1084 && !CONST_INT_P (XEXP (operand, 1))))
1085 LOSE_AND_RETURN ("unexpected multiplicative operand", x);
1087 cris_print_base (reg, file);
1088 fprintf (file, ".%c",
1089 i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b'
1090 : i == 4 ? 'd'
1091 : (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w'
1092 : 'd');
1093 return;
1096 default:
1097 /* No need to handle all strange variants, let output_addr_const
1098 do it for us. */
1099 if (CONSTANT_P (operand))
1101 cris_output_addr_const (file, operand);
1102 return;
1105 LOSE_AND_RETURN ("unexpected operand", x);
1109 static bool
1110 cris_print_operand_punct_valid_p (unsigned char code)
1112 return (code == '#' || code == '!' || code == ':');
1115 /* The PRINT_OPERAND_ADDRESS worker. */
1117 static void
1118 cris_print_operand_address (FILE *file, rtx x)
1120 /* All these were inside MEM:s so output indirection characters. */
1121 putc ('[', file);
1123 if (CONSTANT_ADDRESS_P (x))
1124 cris_output_addr_const (file, x);
1125 else if (BASE_OR_AUTOINCR_P (x))
1126 cris_print_base (x, file);
1127 else if (GET_CODE (x) == PLUS)
1129 rtx x1, x2;
1131 x1 = XEXP (x, 0);
1132 x2 = XEXP (x, 1);
1133 if (BASE_P (x1))
1135 cris_print_base (x1, file);
1136 cris_print_index (x2, file);
1138 else if (BASE_P (x2))
1140 cris_print_base (x2, file);
1141 cris_print_index (x1, file);
1143 else
1144 LOSE_AND_RETURN ("unrecognized address", x);
1146 else if (MEM_P (x))
1148 /* A DIP. Output more indirection characters. */
1149 putc ('[', file);
1150 cris_print_base (XEXP (x, 0), file);
1151 putc (']', file);
1153 else
1154 LOSE_AND_RETURN ("unrecognized address", x);
1156 putc (']', file);
1159 /* The RETURN_ADDR_RTX worker.
1160 We mark that the return address is used, either by EH or
1161 __builtin_return_address, for use by the function prologue and
1162 epilogue. FIXME: This isn't optimal; we just use the mark in the
1163 prologue and epilogue to say that the return address is to be stored
1164 in the stack frame. We could return SRP for leaf-functions and use the
1165 initial-value machinery. */
1168 cris_return_addr_rtx (int count, rtx frameaddr ATTRIBUTE_UNUSED)
1170 cfun->machine->needs_return_address_on_stack = 1;
1172 /* The return-address is stored just above the saved frame-pointer (if
1173 present). Apparently we can't eliminate from the frame-pointer in
1174 that direction, so use the incoming args (maybe pretended) pointer. */
1175 return count == 0
1176 ? gen_rtx_MEM (Pmode, plus_constant (virtual_incoming_args_rtx, -4))
1177 : NULL_RTX;
1180 /* Accessor used in cris.md:return because cfun->machine isn't available
1181 there. */
1183 bool
1184 cris_return_address_on_stack (void)
1186 return df_regs_ever_live_p (CRIS_SRP_REGNUM)
1187 || cfun->machine->needs_return_address_on_stack;
1190 /* Accessor used in cris.md:return because cfun->machine isn't available
1191 there. */
1193 bool
1194 cris_return_address_on_stack_for_return (void)
1196 return cfun->machine->return_type == CRIS_RETINSN_RET ? false
1197 : cris_return_address_on_stack ();
1200 /* This used to be the INITIAL_FRAME_POINTER_OFFSET worker; now only
1201 handles FP -> SP elimination offset. */
1203 static int
1204 cris_initial_frame_pointer_offset (void)
1206 int regno;
1208 /* Initial offset is 0 if we don't have a frame pointer. */
1209 int offs = 0;
1210 bool got_really_used = false;
1212 if (crtl->uses_pic_offset_table)
1214 push_topmost_sequence ();
1215 got_really_used
1216 = reg_used_between_p (pic_offset_table_rtx, get_insns (),
1217 NULL_RTX);
1218 pop_topmost_sequence ();
1221 /* And 4 for each register pushed. */
1222 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1223 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1224 offs += 4;
1226 /* And then, last, we add the locals allocated. */
1227 offs += get_frame_size ();
1229 /* And more; the accumulated args size. */
1230 offs += crtl->outgoing_args_size;
1232 /* Then round it off, in case we use aligned stack. */
1233 if (TARGET_STACK_ALIGN)
1234 offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1;
1236 return offs;
1239 /* The INITIAL_ELIMINATION_OFFSET worker.
1240 Calculate the difference between imaginary registers such as frame
1241 pointer and the stack pointer. Used to eliminate the frame pointer
1242 and imaginary arg pointer. */
1245 cris_initial_elimination_offset (int fromreg, int toreg)
1247 int fp_sp_offset
1248 = cris_initial_frame_pointer_offset ();
1250 /* We should be able to use regs_ever_live and related prologue
1251 information here, or alpha should not as well. */
1252 bool return_address_on_stack = cris_return_address_on_stack ();
1254 /* Here we act as if the frame-pointer were needed. */
1255 int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0);
1257 if (fromreg == ARG_POINTER_REGNUM
1258 && toreg == FRAME_POINTER_REGNUM)
1259 return ap_fp_offset;
1261 /* Between the frame pointer and the stack are only "normal" stack
1262 variables and saved registers. */
1263 if (fromreg == FRAME_POINTER_REGNUM
1264 && toreg == STACK_POINTER_REGNUM)
1265 return fp_sp_offset;
1267 /* We need to balance out the frame pointer here. */
1268 if (fromreg == ARG_POINTER_REGNUM
1269 && toreg == STACK_POINTER_REGNUM)
1270 return ap_fp_offset + fp_sp_offset - 4;
1272 gcc_unreachable ();
1275 /* Worker function for LEGITIMIZE_RELOAD_ADDRESS. */
1277 bool
1278 cris_reload_address_legitimized (rtx x,
1279 enum machine_mode mode ATTRIBUTE_UNUSED,
1280 int opnum ATTRIBUTE_UNUSED,
1281 int itype,
1282 int ind_levels ATTRIBUTE_UNUSED)
1284 enum reload_type type = (enum reload_type) itype;
1285 rtx op0, op1;
1286 rtx *op1p;
1288 if (GET_CODE (x) != PLUS)
1289 return false;
1291 if (TARGET_V32)
1292 return false;
1294 op0 = XEXP (x, 0);
1295 op1 = XEXP (x, 1);
1296 op1p = &XEXP (x, 1);
1298 if (!REG_P (op1))
1299 return false;
1301 if (GET_CODE (op0) == SIGN_EXTEND && MEM_P (XEXP (op0, 0)))
1303 rtx op00 = XEXP (op0, 0);
1304 rtx op000 = XEXP (op00, 0);
1305 rtx *op000p = &XEXP (op00, 0);
1307 if ((GET_MODE (op00) == HImode || GET_MODE (op00) == QImode)
1308 && (REG_P (op000)
1309 || (GET_CODE (op000) == POST_INC && REG_P (XEXP (op000, 0)))))
1311 bool something_reloaded = false;
1313 if (GET_CODE (op000) == POST_INC
1314 && REG_P (XEXP (op000, 0))
1315 && REGNO (XEXP (op000, 0)) > CRIS_LAST_GENERAL_REGISTER)
1316 /* No, this gets too complicated and is too rare to care
1317 about trying to improve on the general code Here.
1318 As the return-value is an all-or-nothing indicator, we
1319 punt on the other register too. */
1320 return false;
1322 if ((REG_P (op000)
1323 && REGNO (op000) > CRIS_LAST_GENERAL_REGISTER))
1325 /* The address of the inner mem is a pseudo or wrong
1326 reg: reload that. */
1327 push_reload (op000, NULL_RTX, op000p, NULL, GENERAL_REGS,
1328 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
1329 something_reloaded = true;
1332 if (REGNO (op1) > CRIS_LAST_GENERAL_REGISTER)
1334 /* Base register is a pseudo or wrong reg: reload it. */
1335 push_reload (op1, NULL_RTX, op1p, NULL, GENERAL_REGS,
1336 GET_MODE (x), VOIDmode, 0, 0,
1337 opnum, type);
1338 something_reloaded = true;
1341 gcc_assert (something_reloaded);
1343 return true;
1347 return false;
1351 /* Worker function for TARGET_PREFERRED_RELOAD_CLASS.
1353 It seems like gcc (2.7.2 and 2.9x of 2000-03-22) may send "NO_REGS" as
1354 the class for a constant (testcase: __Mul in arit.c). To avoid forcing
1355 out a constant into the constant pool, we will trap this case and
1356 return something a bit more sane. FIXME: Check if this is a bug.
1357 Beware that we must not "override" classes that can be specified as
1358 constraint letters, or else asm operands using them will fail when
1359 they need to be reloaded. FIXME: Investigate whether that constitutes
1360 a bug. */
1362 static reg_class_t
1363 cris_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, reg_class_t rclass)
1365 if (rclass != ACR_REGS
1366 && rclass != MOF_REGS
1367 && rclass != SRP_REGS
1368 && rclass != CC0_REGS
1369 && rclass != SPECIAL_REGS)
1370 return GENERAL_REGS;
1372 return rclass;
1375 /* Worker function for TARGET_REGISTER_MOVE_COST. */
1377 static int
1378 cris_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1379 reg_class_t from, reg_class_t to)
1381 /* Can't move to and from a SPECIAL_REGS register, so we have to say
1382 their move cost within that class is higher. How about 7? That's 3
1383 for a move to a GENERAL_REGS register, 3 for the move from the
1384 GENERAL_REGS register, and 1 for the increased register pressure.
1385 Also, it's higher than the memory move cost, as it should.
1386 We also do this for ALL_REGS, since we don't want that class to be
1387 preferred (even to memory) at all where GENERAL_REGS doesn't fit.
1388 Whenever it's about to be used, it's for SPECIAL_REGS. If we don't
1389 present a higher cost for ALL_REGS than memory, a SPECIAL_REGS may be
1390 used when a GENERAL_REGS should be used, even if there are call-saved
1391 GENERAL_REGS left to allocate. This is because the fall-back when
1392 the most preferred register class isn't available, isn't the next
1393 (or next good) wider register class, but the *most widest* register
1394 class. FIXME: pre-IRA comment, perhaps obsolete now. */
1396 if ((reg_classes_intersect_p (from, SPECIAL_REGS)
1397 && reg_classes_intersect_p (to, SPECIAL_REGS))
1398 || from == ALL_REGS || to == ALL_REGS)
1399 return 7;
1401 /* Make moves to/from SPECIAL_REGS slightly more expensive, as we
1402 generally prefer GENERAL_REGS. */
1403 if (reg_classes_intersect_p (from, SPECIAL_REGS)
1404 || reg_classes_intersect_p (to, SPECIAL_REGS))
1405 return 3;
1407 return 2;
1410 /* Worker function for TARGET_MEMORY_MOVE_COST.
1412 This isn't strictly correct for v0..3 in buswidth-8bit mode, but should
1413 suffice. */
1415 static int
1416 cris_memory_move_cost (enum machine_mode mode,
1417 reg_class_t rclass ATTRIBUTE_UNUSED,
1418 bool in ATTRIBUTE_UNUSED)
1420 if (mode == QImode
1421 || mode == HImode)
1422 return 4;
1423 else
1424 return 6;
1427 /* Worker for cris_notice_update_cc; handles the "normal" cases.
1428 FIXME: this code is historical; its functionality should be
1429 refactored to look at insn attributes and moved to
1430 cris_notice_update_cc. Except, we better lose cc0 entirely. */
1432 static void
1433 cris_normal_notice_update_cc (rtx exp, rtx insn)
1435 /* "Normal" means, for:
1436 (set (cc0) (...)):
1437 CC is (...).
1439 (set (reg) (...)):
1440 CC is (reg) and (...) - unless (...) is 0 or reg is a special
1441 register or (v32 and (...) is -32..-1), then CC does not change.
1442 CC_NO_OVERFLOW unless (...) is reg or mem.
1444 (set (mem) (...)):
1445 CC does not change.
1447 (set (pc) (...)):
1448 CC does not change.
1450 (parallel
1451 (set (reg1) (mem (bdap/biap)))
1452 (set (reg2) (bdap/biap))):
1453 CC is (reg1) and (mem (reg2))
1455 (parallel
1456 (set (mem (bdap/biap)) (reg1)) [or 0]
1457 (set (reg2) (bdap/biap))):
1458 CC does not change.
1460 (where reg and mem includes strict_low_parts variants thereof)
1462 For all others, assume CC is clobbered.
1463 Note that we do not have to care about setting CC_NO_OVERFLOW,
1464 since the overflow flag is set to 0 (i.e. right) for
1465 instructions where it does not have any sane sense, but where
1466 other flags have meanings. (This includes shifts; the carry is
1467 not set by them).
1469 Note that there are other parallel constructs we could match,
1470 but we don't do that yet. */
1472 if (GET_CODE (exp) == SET)
1474 /* FIXME: Check when this happens. It looks like we should
1475 actually do a CC_STATUS_INIT here to be safe. */
1476 if (SET_DEST (exp) == pc_rtx)
1477 return;
1479 /* Record CC0 changes, so we do not have to output multiple
1480 test insns. */
1481 if (SET_DEST (exp) == cc0_rtx)
1483 CC_STATUS_INIT;
1485 if (GET_CODE (SET_SRC (exp)) == COMPARE
1486 && XEXP (SET_SRC (exp), 1) == const0_rtx)
1487 cc_status.value1 = XEXP (SET_SRC (exp), 0);
1488 else
1489 cc_status.value1 = SET_SRC (exp);
1491 /* Handle flags for the special btstq on one bit. */
1492 if (GET_CODE (cc_status.value1) == ZERO_EXTRACT
1493 && XEXP (cc_status.value1, 1) == const1_rtx)
1495 if (CONST_INT_P (XEXP (cc_status.value1, 0)))
1496 /* Using cmpq. */
1497 cc_status.flags = CC_INVERTED;
1498 else
1499 /* A one-bit btstq. */
1500 cc_status.flags = CC_Z_IN_NOT_N;
1503 else if (GET_CODE (SET_SRC (exp)) == COMPARE)
1505 if (!REG_P (XEXP (SET_SRC (exp), 0))
1506 && XEXP (SET_SRC (exp), 1) != const0_rtx)
1507 /* For some reason gcc will not canonicalize compare
1508 operations, reversing the sign by itself if
1509 operands are in wrong order. */
1510 /* (But NOT inverted; eq is still eq.) */
1511 cc_status.flags = CC_REVERSED;
1513 /* This seems to be overlooked by gcc. FIXME: Check again.
1514 FIXME: Is it really safe? */
1515 cc_status.value2
1516 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1517 XEXP (SET_SRC (exp), 0),
1518 XEXP (SET_SRC (exp), 1));
1520 return;
1522 else if (REG_P (SET_DEST (exp))
1523 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1524 && REG_P (XEXP (SET_DEST (exp), 0))))
1526 /* A register is set; normally CC is set to show that no
1527 test insn is needed. Catch the exceptions. */
1529 /* If not to cc0, then no "set"s in non-natural mode give
1530 ok cc0... */
1531 if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1532 || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1534 /* ... except add:s and sub:s in DImode. */
1535 if (GET_MODE (SET_DEST (exp)) == DImode
1536 && (GET_CODE (SET_SRC (exp)) == PLUS
1537 || GET_CODE (SET_SRC (exp)) == MINUS))
1539 CC_STATUS_INIT;
1540 cc_status.value1 = SET_DEST (exp);
1541 cc_status.value2 = SET_SRC (exp);
1543 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1544 cc_status.value2))
1545 cc_status.value2 = 0;
1547 /* Add and sub may set V, which gets us
1548 unoptimizable results in "gt" and "le" condition
1549 codes. */
1550 cc_status.flags |= CC_NO_OVERFLOW;
1552 return;
1555 else if (SET_SRC (exp) == const0_rtx
1556 || (REG_P (SET_SRC (exp))
1557 && (REGNO (SET_SRC (exp))
1558 > CRIS_LAST_GENERAL_REGISTER))
1559 || (TARGET_V32
1560 && GET_CODE (SET_SRC (exp)) == CONST_INT
1561 && CRIS_CONST_OK_FOR_LETTER_P (INTVAL (SET_SRC (exp)),
1562 'I')))
1564 /* There's no CC0 change for this case. Just check
1565 for overlap. */
1566 if (cc_status.value1
1567 && modified_in_p (cc_status.value1, insn))
1568 cc_status.value1 = 0;
1570 if (cc_status.value2
1571 && modified_in_p (cc_status.value2, insn))
1572 cc_status.value2 = 0;
1574 return;
1576 else
1578 CC_STATUS_INIT;
1579 cc_status.value1 = SET_DEST (exp);
1580 cc_status.value2 = SET_SRC (exp);
1582 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1583 cc_status.value2))
1584 cc_status.value2 = 0;
1586 /* Some operations may set V, which gets us
1587 unoptimizable results in "gt" and "le" condition
1588 codes. */
1589 if (GET_CODE (SET_SRC (exp)) == PLUS
1590 || GET_CODE (SET_SRC (exp)) == MINUS
1591 || GET_CODE (SET_SRC (exp)) == NEG)
1592 cc_status.flags |= CC_NO_OVERFLOW;
1594 /* For V32, nothing with a register destination sets
1595 C and V usefully. */
1596 if (TARGET_V32)
1597 cc_status.flags |= CC_NO_OVERFLOW;
1599 return;
1602 else if (MEM_P (SET_DEST (exp))
1603 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1604 && MEM_P (XEXP (SET_DEST (exp), 0))))
1606 /* When SET to MEM, then CC is not changed (except for
1607 overlap). */
1608 if (cc_status.value1
1609 && modified_in_p (cc_status.value1, insn))
1610 cc_status.value1 = 0;
1612 if (cc_status.value2
1613 && modified_in_p (cc_status.value2, insn))
1614 cc_status.value2 = 0;
1616 return;
1619 else if (GET_CODE (exp) == PARALLEL)
1621 if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1622 && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1623 && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1625 if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1626 && MEM_P (XEXP (XVECEXP (exp, 0, 0), 1)))
1628 CC_STATUS_INIT;
1630 /* For "move.S [rx=ry+o],rz", say CC reflects
1631 value1=rz and value2=[rx] */
1632 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1633 cc_status.value2
1634 = replace_equiv_address (XEXP (XVECEXP (exp, 0, 0), 1),
1635 XEXP (XVECEXP (exp, 0, 1), 0));
1637 /* Huh? A side-effect cannot change the destination
1638 register. */
1639 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1640 cc_status.value2))
1641 internal_error ("internal error: sideeffect-insn affecting main effect");
1643 /* For V32, moves to registers don't set C and V. */
1644 if (TARGET_V32)
1645 cc_status.flags |= CC_NO_OVERFLOW;
1646 return;
1648 else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1649 || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1650 && MEM_P (XEXP (XVECEXP (exp, 0, 0), 0)))
1652 /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1653 say flags are not changed, except for overlap. */
1654 if (cc_status.value1
1655 && modified_in_p (cc_status.value1, insn))
1656 cc_status.value1 = 0;
1658 if (cc_status.value2
1659 && modified_in_p (cc_status.value2, insn))
1660 cc_status.value2 = 0;
1662 return;
1667 /* If we got here, the case wasn't covered by the code above. */
1668 CC_STATUS_INIT;
1671 /* This function looks into the pattern to see how this insn affects
1672 condition codes.
1674 Used when to eliminate test insns before a condition-code user,
1675 such as a "scc" insn or a conditional branch. This includes
1676 checking if the entities that cc was updated by, are changed by the
1677 operation.
1679 Currently a jumble of the old peek-inside-the-insn and the newer
1680 check-cc-attribute methods. */
1682 void
1683 cris_notice_update_cc (rtx exp, rtx insn)
1685 enum attr_cc attrval = get_attr_cc (insn);
1687 /* Check if user specified "-mcc-init" as a bug-workaround. Remember
1688 to still set CC_REVERSED as below, since that's required by some
1689 compare insn alternatives. (FIXME: GCC should do this virtual
1690 operand swap by itself.) A test-case that may otherwise fail is
1691 gcc.c-torture/execute/20000217-1.c -O0 and -O1. */
1692 if (TARGET_CCINIT)
1694 CC_STATUS_INIT;
1696 if (attrval == CC_REV)
1697 cc_status.flags = CC_REVERSED;
1698 return;
1701 /* Slowly, we're converting to using attributes to control the setting
1702 of condition-code status. */
1703 switch (attrval)
1705 case CC_NONE:
1706 /* Even if it is "none", a setting may clobber a previous
1707 cc-value, so check. */
1708 if (GET_CODE (exp) == SET)
1710 if (cc_status.value1
1711 && modified_in_p (cc_status.value1, insn))
1712 cc_status.value1 = 0;
1714 if (cc_status.value2
1715 && modified_in_p (cc_status.value2, insn))
1716 cc_status.value2 = 0;
1718 return;
1720 case CC_CLOBBER:
1721 CC_STATUS_INIT;
1722 return;
1724 case CC_REV:
1725 case CC_NOOV32:
1726 case CC_NORMAL:
1727 cris_normal_notice_update_cc (exp, insn);
1729 /* The "test" insn doesn't clear (carry and) overflow on V32. We
1730 can change bge => bpl and blt => bmi by passing on to the cc0
1731 user that V should not be considered; bgt and ble are taken
1732 care of by other methods (see {tst,cmp}{si,hi,qi}). */
1733 if (attrval == CC_NOOV32 && TARGET_V32)
1734 cc_status.flags |= CC_NO_OVERFLOW;
1735 return;
1737 default:
1738 internal_error ("unknown cc_attr value");
1741 CC_STATUS_INIT;
1744 /* Return != 0 if the return sequence for the current function is short,
1745 like "ret" or "jump [sp+]". Prior to reloading, we can't tell if
1746 registers must be saved, so return 0 then. */
1748 bool
1749 cris_simple_epilogue (void)
1751 unsigned int regno;
1752 unsigned int reglimit = STACK_POINTER_REGNUM;
1753 bool got_really_used = false;
1755 if (! reload_completed
1756 || frame_pointer_needed
1757 || get_frame_size () != 0
1758 || crtl->args.pretend_args_size
1759 || crtl->args.size
1760 || crtl->outgoing_args_size
1761 || crtl->calls_eh_return
1763 /* If we're not supposed to emit prologue and epilogue, we must
1764 not emit return-type instructions. */
1765 || !TARGET_PROLOGUE_EPILOGUE)
1766 return false;
1768 /* Can't return from stacked return address with v32. */
1769 if (TARGET_V32 && cris_return_address_on_stack ())
1770 return false;
1772 if (crtl->uses_pic_offset_table)
1774 push_topmost_sequence ();
1775 got_really_used
1776 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
1777 pop_topmost_sequence ();
1780 /* No simple epilogue if there are saved registers. */
1781 for (regno = 0; regno < reglimit; regno++)
1782 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1783 return false;
1785 return true;
1788 /* Expand a return insn (just one insn) marked as using SRP or stack
1789 slot depending on parameter ON_STACK. */
1791 void
1792 cris_expand_return (bool on_stack)
1794 /* FIXME: emit a parallel with a USE for SRP or the stack-slot, to
1795 tell "ret" from "jump [sp+]". Some, but not all, other parts of
1796 GCC expect just (return) to do the right thing when optimizing, so
1797 we do that until they're fixed. Currently, all return insns in a
1798 function must be the same (not really a limiting factor) so we need
1799 to check that it doesn't change half-way through. */
1800 emit_jump_insn (ret_rtx);
1802 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_RET || !on_stack);
1803 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_JUMP || on_stack);
1805 cfun->machine->return_type
1806 = on_stack ? CRIS_RETINSN_JUMP : CRIS_RETINSN_RET;
1809 /* Compute a (partial) cost for rtx X. Return true if the complete
1810 cost has been computed, and false if subexpressions should be
1811 scanned. In either case, *TOTAL contains the cost result. */
1813 static bool
1814 cris_rtx_costs (rtx x, int code, int outer_code, int opno, int *total,
1815 bool speed)
1817 switch (code)
1819 case CONST_INT:
1821 HOST_WIDE_INT val = INTVAL (x);
1822 if (val == 0)
1823 *total = 0;
1824 else if (val < 32 && val >= -32)
1825 *total = 1;
1826 /* Eight or 16 bits are a word and cycle more expensive. */
1827 else if (val <= 32767 && val >= -32768)
1828 *total = 2;
1829 /* A 32-bit constant (or very seldom, unsigned 16 bits) costs
1830 another word. FIXME: This isn't linear to 16 bits. */
1831 else
1832 *total = 4;
1833 return true;
1836 case LABEL_REF:
1837 *total = 6;
1838 return true;
1840 case CONST:
1841 case SYMBOL_REF:
1842 *total = 6;
1843 return true;
1845 case CONST_DOUBLE:
1846 if (x != CONST0_RTX (GET_MODE (x) == VOIDmode ? DImode : GET_MODE (x)))
1847 *total = 12;
1848 else
1849 /* Make 0.0 cheap, else test-insns will not be used. */
1850 *total = 0;
1851 return true;
1853 case MULT:
1854 /* If we have one arm of an ADDI, make sure it gets the cost of
1855 one insn, i.e. zero cost for this operand, and just the cost
1856 of the PLUS, as the insn is created by combine from a PLUS
1857 and an ASHIFT, and the MULT cost below would make the
1858 combined value be larger than the separate insns. The insn
1859 validity is checked elsewhere by combine.
1861 FIXME: this case is a stop-gap for 4.3 and 4.4, this whole
1862 function should be rewritten. */
1863 if (outer_code == PLUS && BIAP_INDEX_P (x))
1865 *total = 0;
1866 return true;
1869 /* Identify values that are no powers of two. Powers of 2 are
1870 taken care of already and those values should not be changed. */
1871 if (!CONST_INT_P (XEXP (x, 1))
1872 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1874 /* If we have a multiply insn, then the cost is between
1875 1 and 2 "fast" instructions. */
1876 if (TARGET_HAS_MUL_INSNS)
1878 *total = COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2;
1879 return true;
1882 /* Estimate as 4 + 4 * #ofbits. */
1883 *total = COSTS_N_INSNS (132);
1884 return true;
1886 return false;
1888 case UDIV:
1889 case MOD:
1890 case UMOD:
1891 case DIV:
1892 if (!CONST_INT_P (XEXP (x, 1))
1893 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1895 /* Estimate this as 4 + 8 * #of bits. */
1896 *total = COSTS_N_INSNS (260);
1897 return true;
1899 return false;
1901 case AND:
1902 if (CONST_INT_P (XEXP (x, 1))
1903 /* Two constants may actually happen before optimization. */
1904 && !CONST_INT_P (XEXP (x, 0))
1905 && !CRIS_CONST_OK_FOR_LETTER_P (INTVAL (XEXP (x, 1)), 'I'))
1907 *total
1908 = (rtx_cost (XEXP (x, 0), (enum rtx_code) outer_code,
1909 opno, speed) + 2
1910 + 2 * GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))));
1911 return true;
1913 return false;
1915 case ZERO_EXTRACT:
1916 if (outer_code != COMPARE)
1917 return false;
1918 /* fall through */
1920 case ZERO_EXTEND: case SIGN_EXTEND:
1921 *total = rtx_cost (XEXP (x, 0), (enum rtx_code) outer_code, opno, speed);
1922 return true;
1924 default:
1925 return false;
1929 /* The ADDRESS_COST worker. */
1931 static int
1932 cris_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
1934 /* The metric to use for the cost-macros is unclear.
1935 The metric used here is (the number of cycles needed) / 2,
1936 where we consider equal a cycle for a word of code and a cycle to
1937 read memory. FIXME: Adding "+ 1" to all values would avoid
1938 returning 0, as tree-ssa-loop-ivopts.c as of r128272 "normalizes"
1939 0 to 1, thereby giving equal costs to [rN + rM] and [rN].
1940 Unfortunately(?) such a hack would expose other pessimizations,
1941 at least with g++.dg/tree-ssa/ivopts-1.C, adding insns to the
1942 loop there, without apparent reason. */
1944 /* The cheapest addressing modes get 0, since nothing extra is needed. */
1945 if (BASE_OR_AUTOINCR_P (x))
1946 return 0;
1948 /* An indirect mem must be a DIP. This means two bytes extra for code,
1949 and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */
1950 if (MEM_P (x))
1951 return (2 + 4) / 2;
1953 /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
1954 an extra DIP prefix and 4 bytes of constant in most cases. */
1955 if (CONSTANT_P (x))
1956 return (2 + 4) / 2;
1958 /* Handle BIAP and BDAP prefixes. */
1959 if (GET_CODE (x) == PLUS)
1961 rtx tem1 = XEXP (x, 0);
1962 rtx tem2 = XEXP (x, 1);
1964 /* Local extended canonicalization rule: the first operand must
1965 be REG, unless it's an operation (MULT). */
1966 if (!REG_P (tem1) && GET_CODE (tem1) != MULT)
1967 tem1 = tem2, tem2 = XEXP (x, 0);
1969 /* We'll "assume" we have canonical RTX now. */
1970 gcc_assert (REG_P (tem1) || GET_CODE (tem1) == MULT);
1972 /* A BIAP is 2 extra bytes for the prefix insn, nothing more. We
1973 recognize the typical MULT which is always in tem1 because of
1974 insn canonicalization. */
1975 if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
1976 || REG_P (tem2))
1977 return 2 / 2;
1979 /* A BDAP (quick) is 2 extra bytes. Any constant operand to the
1980 PLUS is always found in tem2. */
1981 if (CONST_INT_P (tem2) && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
1982 return 2 / 2;
1984 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
1985 bytes. */
1986 if (CONST_INT_P (tem2)
1987 && CRIS_CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
1988 return (2 + 2) / 2;
1990 /* A BDAP with some other constant is 2 bytes extra. */
1991 if (CONSTANT_P (tem2))
1992 return (2 + 2 + 2) / 2;
1994 /* BDAP with something indirect should have a higher cost than
1995 BIAP with register. FIXME: Should it cost like a MEM or more? */
1996 return (2 + 2 + 2) / 2;
1999 /* What else? Return a high cost. It matters only for valid
2000 addressing modes. */
2001 return 10;
2004 /* Check various objections to the side-effect. Used in the test-part
2005 of an anonymous insn describing an insn with a possible side-effect.
2006 Returns nonzero if the implied side-effect is ok.
2008 code : PLUS or MULT
2009 ops : An array of rtx:es. lreg, rreg, rval,
2010 The variables multop and other_op are indexes into this,
2011 or -1 if they are not applicable.
2012 lreg : The register that gets assigned in the side-effect.
2013 rreg : One register in the side-effect expression
2014 rval : The other register, or an int.
2015 multop : An integer to multiply rval with.
2016 other_op : One of the entities of the main effect,
2017 whose mode we must consider. */
2020 cris_side_effect_mode_ok (enum rtx_code code, rtx *ops,
2021 int lreg, int rreg, int rval,
2022 int multop, int other_op)
2024 /* Find what value to multiply with, for rx =ry + rz * n. */
2025 int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
2027 rtx reg_rtx = ops[rreg];
2028 rtx val_rtx = ops[rval];
2030 /* The operands may be swapped. Canonicalize them in reg_rtx and
2031 val_rtx, where reg_rtx always is a reg (for this constraint to
2032 match). */
2033 if (! BASE_P (reg_rtx))
2034 reg_rtx = val_rtx, val_rtx = ops[rreg];
2036 /* Don't forget to check that reg_rtx really is a reg. If it isn't,
2037 we have no business. */
2038 if (! BASE_P (reg_rtx))
2039 return 0;
2041 /* Don't do this when -mno-split. */
2042 if (!TARGET_SIDE_EFFECT_PREFIXES)
2043 return 0;
2045 /* The mult expression may be hidden in lreg. FIXME: Add more
2046 commentary about that. */
2047 if (GET_CODE (val_rtx) == MULT)
2049 mult = INTVAL (XEXP (val_rtx, 1));
2050 val_rtx = XEXP (val_rtx, 0);
2051 code = MULT;
2054 /* First check the "other operand". */
2055 if (other_op >= 0)
2057 if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
2058 return 0;
2060 /* Check if the lvalue register is the same as the "other
2061 operand". If so, the result is undefined and we shouldn't do
2062 this. FIXME: Check again. */
2063 if ((BASE_P (ops[lreg])
2064 && BASE_P (ops[other_op])
2065 && REGNO (ops[lreg]) == REGNO (ops[other_op]))
2066 || rtx_equal_p (ops[other_op], ops[lreg]))
2067 return 0;
2070 /* Do not accept frame_pointer_rtx as any operand. */
2071 if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
2072 || ops[rval] == frame_pointer_rtx
2073 || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
2074 return 0;
2076 if (code == PLUS
2077 && ! BASE_P (val_rtx))
2080 /* Do not allow rx = rx + n if a normal add or sub with same size
2081 would do. */
2082 if (rtx_equal_p (ops[lreg], reg_rtx)
2083 && CONST_INT_P (val_rtx)
2084 && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2085 return 0;
2087 /* Check allowed cases, like [r(+)?].[bwd] and const. */
2088 if (CONSTANT_P (val_rtx))
2089 return 1;
2091 if (MEM_P (val_rtx) && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
2092 return 1;
2094 if (GET_CODE (val_rtx) == SIGN_EXTEND
2095 && MEM_P (XEXP (val_rtx, 0))
2096 && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
2097 return 1;
2099 /* If we got here, it's not a valid addressing mode. */
2100 return 0;
2102 else if (code == MULT
2103 || (code == PLUS && BASE_P (val_rtx)))
2105 /* Do not allow rx = rx + ry.S, since it doesn't give better code. */
2106 if (rtx_equal_p (ops[lreg], reg_rtx)
2107 || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2108 return 0;
2110 /* Do not allow bad multiply-values. */
2111 if (mult != 1 && mult != 2 && mult != 4)
2112 return 0;
2114 /* Only allow r + ... */
2115 if (! BASE_P (reg_rtx))
2116 return 0;
2118 /* If we got here, all seems ok.
2119 (All checks need to be done above). */
2120 return 1;
2123 /* If we get here, the caller got its initial tests wrong. */
2124 internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
2127 /* Whether next_cc0_user of insn is LE or GT or requires a real compare
2128 insn for other reasons. */
2130 bool
2131 cris_cc0_user_requires_cmp (rtx insn)
2133 rtx cc0_user = NULL;
2134 rtx body;
2135 rtx set;
2137 gcc_assert (insn != NULL);
2139 if (!TARGET_V32)
2140 return false;
2142 cc0_user = next_cc0_user (insn);
2143 if (cc0_user == NULL)
2144 return false;
2146 body = PATTERN (cc0_user);
2147 set = single_set (cc0_user);
2149 /* Users can be sCC and bCC. */
2150 if (JUMP_P (cc0_user)
2151 && GET_CODE (body) == SET
2152 && SET_DEST (body) == pc_rtx
2153 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2154 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx)
2156 return
2157 GET_CODE (XEXP (SET_SRC (body), 0)) == GT
2158 || GET_CODE (XEXP (SET_SRC (body), 0)) == LE;
2160 else if (set)
2162 return
2163 GET_CODE (SET_SRC (body)) == GT
2164 || GET_CODE (SET_SRC (body)) == LE;
2167 gcc_unreachable ();
2170 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2171 does not handle the case where the IN operand is strict_low_part; it
2172 does handle it for X. Test-case in Axis-20010516. This function takes
2173 care of that for THIS port. FIXME: strict_low_part is going away
2174 anyway. */
2176 static int
2177 cris_reg_overlap_mentioned_p (rtx x, rtx in)
2179 /* The function reg_overlap_mentioned now handles when X is
2180 strict_low_part, but not when IN is a STRICT_LOW_PART. */
2181 if (GET_CODE (in) == STRICT_LOW_PART)
2182 in = XEXP (in, 0);
2184 return reg_overlap_mentioned_p (x, in);
2187 /* The TARGET_ASM_NAMED_SECTION worker.
2188 We just dispatch to the functions for ELF and a.out. */
2190 void
2191 cris_target_asm_named_section (const char *name, unsigned int flags,
2192 tree decl)
2194 if (! TARGET_ELF)
2195 default_no_named_section (name, flags, decl);
2196 else
2197 default_elf_asm_named_section (name, flags, decl);
2200 /* Return TRUE iff X is a CONST valid for e.g. indexing.
2201 ANY_OPERAND is 0 if X is in a CALL_P insn or movsi, 1
2202 elsewhere. */
2204 bool
2205 cris_valid_pic_const (rtx x, bool any_operand)
2207 gcc_assert (flag_pic);
2209 switch (GET_CODE (x))
2211 case CONST_INT:
2212 case CONST_DOUBLE:
2213 return true;
2214 default:
2218 if (GET_CODE (x) != CONST)
2219 return false;
2221 x = XEXP (x, 0);
2223 /* Handle (const (plus (unspec .. UNSPEC_GOTREL) (const_int ...))). */
2224 if (GET_CODE (x) == PLUS
2225 && GET_CODE (XEXP (x, 0)) == UNSPEC
2226 && (XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREL
2227 || XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_PCREL)
2228 && CONST_INT_P (XEXP (x, 1)))
2229 x = XEXP (x, 0);
2231 if (GET_CODE (x) == UNSPEC)
2232 switch (XINT (x, 1))
2234 /* A PCREL operand is only valid for call and movsi. */
2235 case CRIS_UNSPEC_PLT_PCREL:
2236 case CRIS_UNSPEC_PCREL:
2237 return !any_operand;
2239 case CRIS_UNSPEC_PLT_GOTREL:
2240 case CRIS_UNSPEC_PLTGOTREAD:
2241 case CRIS_UNSPEC_GOTREAD:
2242 case CRIS_UNSPEC_GOTREL:
2243 return true;
2244 default:
2245 gcc_unreachable ();
2248 return cris_pic_symbol_type_of (x) == cris_no_symbol;
2251 /* Helper function to find the right PIC-type symbol to generate,
2252 given the original (non-PIC) representation. */
2254 enum cris_pic_symbol_type
2255 cris_pic_symbol_type_of (rtx x)
2257 switch (GET_CODE (x))
2259 case SYMBOL_REF:
2260 return SYMBOL_REF_LOCAL_P (x)
2261 ? cris_rel_symbol : cris_got_symbol;
2263 case LABEL_REF:
2264 return cris_rel_symbol;
2266 case CONST:
2267 return cris_pic_symbol_type_of (XEXP (x, 0));
2269 case PLUS:
2270 case MINUS:
2272 enum cris_pic_symbol_type t1 = cris_pic_symbol_type_of (XEXP (x, 0));
2273 enum cris_pic_symbol_type t2 = cris_pic_symbol_type_of (XEXP (x, 1));
2275 gcc_assert (t1 == cris_no_symbol || t2 == cris_no_symbol);
2277 if (t1 == cris_got_symbol || t1 == cris_got_symbol)
2278 return cris_got_symbol_needing_fixup;
2280 return t1 != cris_no_symbol ? t1 : t2;
2283 case CONST_INT:
2284 case CONST_DOUBLE:
2285 return cris_no_symbol;
2287 case UNSPEC:
2288 /* Likely an offsettability-test attempting to add a constant to
2289 a GOTREAD symbol, which can't be handled. */
2290 return cris_invalid_pic_symbol;
2292 default:
2293 fatal_insn ("unrecognized supposed constant", x);
2296 gcc_unreachable ();
2299 /* The LEGITIMATE_PIC_OPERAND_P worker. */
2302 cris_legitimate_pic_operand (rtx x)
2304 /* Symbols are not valid PIC operands as-is; just constants. */
2305 return cris_valid_pic_const (x, true);
2308 /* The ASM_OUTPUT_CASE_END worker. */
2310 void
2311 cris_asm_output_case_end (FILE *stream, int num, rtx table)
2313 /* Step back, over the label for the table, to the actual casejump and
2314 assert that we find only what's expected. */
2315 rtx whole_jump_insn = prev_nonnote_nondebug_insn (table);
2316 gcc_assert (whole_jump_insn != NULL_RTX && LABEL_P (whole_jump_insn));
2317 whole_jump_insn = prev_nonnote_nondebug_insn (whole_jump_insn);
2318 gcc_assert (whole_jump_insn != NULL_RTX
2319 && (JUMP_P (whole_jump_insn)
2320 || (TARGET_V32 && INSN_P (whole_jump_insn)
2321 && GET_CODE (PATTERN (whole_jump_insn)) == SEQUENCE)));
2322 /* Get the pattern of the casejump, so we can extract the default label. */
2323 whole_jump_insn = PATTERN (whole_jump_insn);
2325 if (TARGET_V32)
2327 /* This can be a SEQUENCE, meaning the delay-slot of the jump is
2328 filled. We also output the offset word a little differently. */
2329 rtx parallel_jump
2330 = (GET_CODE (whole_jump_insn) == SEQUENCE
2331 ? PATTERN (XVECEXP (whole_jump_insn, 0, 0)) : whole_jump_insn);
2333 asm_fprintf (stream,
2334 "\t.word %LL%d-.%s\n",
2335 CODE_LABEL_NUMBER (XEXP (XEXP (XEXP (XVECEXP
2336 (parallel_jump, 0, 0),
2337 1), 2), 0)),
2338 (TARGET_PDEBUG ? "; default" : ""));
2339 return;
2342 asm_fprintf (stream,
2343 "\t.word %LL%d-%LL%d%s\n",
2344 CODE_LABEL_NUMBER (XEXP
2345 (XEXP
2346 (XEXP (XVECEXP (whole_jump_insn, 0, 0), 1),
2347 2), 0)),
2348 num,
2349 (TARGET_PDEBUG ? "; default" : ""));
2352 /* The TARGET_OPTION_OVERRIDE worker.
2353 As is the norm, this also parses -mfoo=bar type parameters. */
2355 static void
2356 cris_option_override (void)
2358 if (cris_max_stackframe_str)
2360 cris_max_stackframe = atoi (cris_max_stackframe_str);
2362 /* Do some sanity checking. */
2363 if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2364 internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2365 cris_max_stackframe, 0x20000000);
2368 /* Let "-metrax4" and "-metrax100" change the cpu version. */
2369 if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2370 cris_cpu_version = CRIS_CPU_SVINTO;
2371 else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2372 cris_cpu_version = CRIS_CPU_ETRAX4;
2374 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2375 if (cris_cpu_str)
2377 cris_cpu_version
2378 = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2380 if (strcmp ("etrax4", cris_cpu_str) == 0)
2381 cris_cpu_version = 3;
2383 if (strcmp ("svinto", cris_cpu_str) == 0
2384 || strcmp ("etrax100", cris_cpu_str) == 0)
2385 cris_cpu_version = 8;
2387 if (strcmp ("ng", cris_cpu_str) == 0
2388 || strcmp ("etrax100lx", cris_cpu_str) == 0)
2389 cris_cpu_version = 10;
2391 if (cris_cpu_version < 0 || cris_cpu_version > 32)
2392 error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2393 cris_cpu_str);
2395 /* Set the target flags. */
2396 if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2397 target_flags |= MASK_ETRAX4_ADD;
2399 /* If this is Svinto or higher, align for 32 bit accesses. */
2400 if (cris_cpu_version >= CRIS_CPU_SVINTO)
2401 target_flags
2402 |= (MASK_SVINTO | MASK_ALIGN_BY_32
2403 | MASK_STACK_ALIGN | MASK_CONST_ALIGN
2404 | MASK_DATA_ALIGN);
2406 /* Note that we do not add new flags when it can be completely
2407 described with a macro that uses -mcpu=X. So
2408 TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */
2411 if (cris_tune_str)
2413 int cris_tune
2414 = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2416 if (strcmp ("etrax4", cris_tune_str) == 0)
2417 cris_tune = 3;
2419 if (strcmp ("svinto", cris_tune_str) == 0
2420 || strcmp ("etrax100", cris_tune_str) == 0)
2421 cris_tune = 8;
2423 if (strcmp ("ng", cris_tune_str) == 0
2424 || strcmp ("etrax100lx", cris_tune_str) == 0)
2425 cris_tune = 10;
2427 if (cris_tune < 0 || cris_tune > 32)
2428 error ("unknown CRIS cpu version specification in -mtune= : %s",
2429 cris_tune_str);
2431 if (cris_tune >= CRIS_CPU_SVINTO)
2432 /* We have currently nothing more to tune than alignment for
2433 memory accesses. */
2434 target_flags
2435 |= (MASK_STACK_ALIGN | MASK_CONST_ALIGN
2436 | MASK_DATA_ALIGN | MASK_ALIGN_BY_32);
2439 if (cris_cpu_version >= CRIS_CPU_V32)
2440 target_flags &= ~(MASK_SIDE_EFFECT_PREFIXES|MASK_MUL_BUG);
2442 if (flag_pic)
2444 /* Use error rather than warning, so invalid use is easily
2445 detectable. Still change to the values we expect, to avoid
2446 further errors. */
2447 if (! TARGET_LINUX)
2449 error ("-fPIC and -fpic are not supported in this configuration");
2450 flag_pic = 0;
2453 /* Turn off function CSE. We need to have the addresses reach the
2454 call expanders to get PLT-marked, as they could otherwise be
2455 compared against zero directly or indirectly. After visiting the
2456 call expanders they will then be cse:ed, as the call expanders
2457 force_reg the addresses, effectively forcing flag_no_function_cse
2458 to 0. */
2459 flag_no_function_cse = 1;
2462 if (write_symbols == DWARF2_DEBUG && ! TARGET_ELF)
2464 warning (0, "that particular -g option is invalid with -maout and -melinux");
2465 write_symbols = DBX_DEBUG;
2468 /* Set the per-function-data initializer. */
2469 init_machine_status = cris_init_machine_status;
2472 /* The TARGET_ASM_OUTPUT_MI_THUNK worker. */
2474 static void
2475 cris_asm_output_mi_thunk (FILE *stream,
2476 tree thunkdecl ATTRIBUTE_UNUSED,
2477 HOST_WIDE_INT delta,
2478 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
2479 tree funcdecl)
2481 if (delta > 0)
2482 fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2483 ADDITIVE_SIZE_MODIFIER (delta), delta,
2484 reg_names[CRIS_FIRST_ARG_REG]);
2485 else if (delta < 0)
2486 fprintf (stream, "\tsub%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2487 ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2488 reg_names[CRIS_FIRST_ARG_REG]);
2490 if (flag_pic)
2492 const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2494 name = (* targetm.strip_name_encoding) (name);
2496 if (TARGET_V32)
2498 fprintf (stream, "\tba ");
2499 assemble_name (stream, name);
2500 fprintf (stream, "%s\n", CRIS_PLT_PCOFFSET_SUFFIX);
2502 else
2504 fprintf (stream, "add.d ");
2505 assemble_name (stream, name);
2506 fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2509 else
2511 fprintf (stream, "jump ");
2512 assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2513 fprintf (stream, "\n");
2515 if (TARGET_V32)
2516 fprintf (stream, "\tnop\n");
2520 /* Boilerplate emitted at start of file.
2522 NO_APP *only at file start* means faster assembly. It also means
2523 comments are not allowed. In some cases comments will be output
2524 for debugging purposes. Make sure they are allowed then.
2526 We want a .file directive only if TARGET_ELF. */
2527 static void
2528 cris_file_start (void)
2530 /* These expressions can vary at run time, so we cannot put
2531 them into TARGET_INITIALIZER. */
2532 targetm.asm_file_start_app_off = !(TARGET_PDEBUG || flag_print_asm_name);
2533 targetm.asm_file_start_file_directive = TARGET_ELF;
2535 default_file_start ();
2538 /* Rename the function calls for integer multiply and divide. */
2539 static void
2540 cris_init_libfuncs (void)
2542 set_optab_libfunc (smul_optab, SImode, "__Mul");
2543 set_optab_libfunc (sdiv_optab, SImode, "__Div");
2544 set_optab_libfunc (udiv_optab, SImode, "__Udiv");
2545 set_optab_libfunc (smod_optab, SImode, "__Mod");
2546 set_optab_libfunc (umod_optab, SImode, "__Umod");
2549 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2550 mark functions. */
2552 void
2553 cris_init_expanders (void)
2555 /* Nothing here at the moment. */
2558 /* Zero initialization is OK for all current fields. */
2560 static struct machine_function *
2561 cris_init_machine_status (void)
2563 return ggc_alloc_cleared_machine_function ();
2566 /* Split a 2 word move (DI or presumably DF) into component parts.
2567 Originally a copy of gen_split_move_double in m32r.c. */
2570 cris_split_movdx (rtx *operands)
2572 enum machine_mode mode = GET_MODE (operands[0]);
2573 rtx dest = operands[0];
2574 rtx src = operands[1];
2575 rtx val;
2577 /* We used to have to handle (SUBREG (MEM)) here, but that should no
2578 longer happen; after reload there are no SUBREGs any more, and we're
2579 only called after reload. */
2580 CRIS_ASSERT (GET_CODE (dest) != SUBREG && GET_CODE (src) != SUBREG);
2582 start_sequence ();
2583 if (REG_P (dest))
2585 int dregno = REGNO (dest);
2587 /* Reg-to-reg copy. */
2588 if (REG_P (src))
2590 int sregno = REGNO (src);
2592 int reverse = (dregno == sregno + 1);
2594 /* We normally copy the low-numbered register first. However, if
2595 the first register operand 0 is the same as the second register of
2596 operand 1, we must copy in the opposite order. */
2597 emit_insn (gen_rtx_SET (VOIDmode,
2598 operand_subword (dest, reverse, TRUE, mode),
2599 operand_subword (src, reverse, TRUE, mode)));
2601 emit_insn (gen_rtx_SET (VOIDmode,
2602 operand_subword (dest, !reverse, TRUE, mode),
2603 operand_subword (src, !reverse, TRUE, mode)));
2605 /* Constant-to-reg copy. */
2606 else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE)
2608 rtx words[2];
2609 split_double (src, &words[0], &words[1]);
2610 emit_insn (gen_rtx_SET (VOIDmode,
2611 operand_subword (dest, 0, TRUE, mode),
2612 words[0]));
2614 emit_insn (gen_rtx_SET (VOIDmode,
2615 operand_subword (dest, 1, TRUE, mode),
2616 words[1]));
2618 /* Mem-to-reg copy. */
2619 else if (MEM_P (src))
2621 /* If the high-address word is used in the address, we must load it
2622 last. Otherwise, load it first. */
2623 rtx addr = XEXP (src, 0);
2624 int reverse
2625 = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2627 /* The original code implies that we can't do
2628 move.x [rN+],rM move.x [rN],rM+1
2629 when rN is dead, because of REG_NOTES damage. That is
2630 consistent with what I've seen, so don't try it.
2632 We have two different cases here; if the addr is POST_INC,
2633 just pass it through, otherwise add constants. */
2635 if (GET_CODE (addr) == POST_INC)
2637 rtx mem;
2638 rtx insn;
2640 /* Whenever we emit insns with post-incremented
2641 addresses ourselves, we must add a post-inc note
2642 manually. */
2643 mem = change_address (src, SImode, addr);
2644 insn
2645 = gen_rtx_SET (VOIDmode,
2646 operand_subword (dest, 0, TRUE, mode), mem);
2647 insn = emit_insn (insn);
2648 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2649 REG_NOTES (insn)
2650 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2651 REG_NOTES (insn));
2653 mem = copy_rtx (mem);
2654 insn
2655 = gen_rtx_SET (VOIDmode,
2656 operand_subword (dest, 1, TRUE, mode), mem);
2657 insn = emit_insn (insn);
2658 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2659 REG_NOTES (insn)
2660 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2661 REG_NOTES (insn));
2663 else
2665 /* Make sure we don't get any other addresses with
2666 embedded postincrements. They should be stopped in
2667 GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2668 safety. */
2669 if (side_effects_p (addr))
2670 fatal_insn ("unexpected side-effects in address", addr);
2672 emit_insn (gen_rtx_SET
2673 (VOIDmode,
2674 operand_subword (dest, reverse, TRUE, mode),
2675 change_address
2676 (src, SImode,
2677 plus_constant (addr,
2678 reverse * UNITS_PER_WORD))));
2679 emit_insn (gen_rtx_SET
2680 (VOIDmode,
2681 operand_subword (dest, ! reverse, TRUE, mode),
2682 change_address
2683 (src, SImode,
2684 plus_constant (addr,
2685 (! reverse) *
2686 UNITS_PER_WORD))));
2689 else
2690 internal_error ("unknown src");
2692 /* Reg-to-mem copy or clear mem. */
2693 else if (MEM_P (dest)
2694 && (REG_P (src)
2695 || src == const0_rtx
2696 || src == CONST0_RTX (DFmode)))
2698 rtx addr = XEXP (dest, 0);
2700 if (GET_CODE (addr) == POST_INC)
2702 rtx mem;
2703 rtx insn;
2705 /* Whenever we emit insns with post-incremented addresses
2706 ourselves, we must add a post-inc note manually. */
2707 mem = change_address (dest, SImode, addr);
2708 insn
2709 = gen_rtx_SET (VOIDmode,
2710 mem, operand_subword (src, 0, TRUE, mode));
2711 insn = emit_insn (insn);
2712 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2713 REG_NOTES (insn)
2714 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2715 REG_NOTES (insn));
2717 mem = copy_rtx (mem);
2718 insn
2719 = gen_rtx_SET (VOIDmode,
2720 mem,
2721 operand_subword (src, 1, TRUE, mode));
2722 insn = emit_insn (insn);
2723 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2724 REG_NOTES (insn)
2725 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2726 REG_NOTES (insn));
2728 else
2730 /* Make sure we don't get any other addresses with embedded
2731 postincrements. They should be stopped in
2732 GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */
2733 if (side_effects_p (addr))
2734 fatal_insn ("unexpected side-effects in address", addr);
2736 emit_insn (gen_rtx_SET
2737 (VOIDmode,
2738 change_address (dest, SImode, addr),
2739 operand_subword (src, 0, TRUE, mode)));
2741 emit_insn (gen_rtx_SET
2742 (VOIDmode,
2743 change_address (dest, SImode,
2744 plus_constant (addr,
2745 UNITS_PER_WORD)),
2746 operand_subword (src, 1, TRUE, mode)));
2750 else
2751 internal_error ("unknown dest");
2753 val = get_insns ();
2754 end_sequence ();
2755 return val;
2758 /* The expander for the prologue pattern name. */
2760 void
2761 cris_expand_prologue (void)
2763 int regno;
2764 int size = get_frame_size ();
2765 /* Shorten the used name for readability. */
2766 int cfoa_size = crtl->outgoing_args_size;
2767 int last_movem_reg = -1;
2768 int framesize = 0;
2769 rtx mem, insn;
2770 int return_address_on_stack = cris_return_address_on_stack ();
2771 int got_really_used = false;
2772 int n_movem_regs = 0;
2773 int pretend = crtl->args.pretend_args_size;
2775 /* Don't do anything if no prologues or epilogues are wanted. */
2776 if (!TARGET_PROLOGUE_EPILOGUE)
2777 return;
2779 CRIS_ASSERT (size >= 0);
2781 if (crtl->uses_pic_offset_table)
2783 /* A reference may have been optimized out (like the abort () in
2784 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
2785 it's still used. */
2786 push_topmost_sequence ();
2787 got_really_used
2788 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
2789 pop_topmost_sequence ();
2792 /* Align the size to what's best for the CPU model. */
2793 if (TARGET_STACK_ALIGN)
2794 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
2796 if (pretend)
2798 /* See also cris_setup_incoming_varargs where
2799 cfun->machine->stdarg_regs is set. There are other setters of
2800 crtl->args.pretend_args_size than stdarg handling, like
2801 for an argument passed with parts in R13 and stack. We must
2802 not store R13 into the pretend-area for that case, as GCC does
2803 that itself. "Our" store would be marked as redundant and GCC
2804 will attempt to remove it, which will then be flagged as an
2805 internal error; trying to remove a frame-related insn. */
2806 int stdarg_regs = cfun->machine->stdarg_regs;
2808 framesize += pretend;
2810 for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
2811 stdarg_regs > 0;
2812 regno--, pretend -= 4, stdarg_regs--)
2814 insn = emit_insn (gen_rtx_SET (VOIDmode,
2815 stack_pointer_rtx,
2816 plus_constant (stack_pointer_rtx,
2817 -4)));
2818 /* FIXME: When dwarf2 frame output and unless asynchronous
2819 exceptions, make dwarf2 bundle together all stack
2820 adjustments like it does for registers between stack
2821 adjustments. */
2822 RTX_FRAME_RELATED_P (insn) = 1;
2824 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2825 set_mem_alias_set (mem, get_varargs_alias_set ());
2826 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2828 /* Note the absence of RTX_FRAME_RELATED_P on the above insn:
2829 the value isn't restored, so we don't want to tell dwarf2
2830 that it's been stored to stack, else EH handling info would
2831 get confused. */
2834 /* For other setters of crtl->args.pretend_args_size, we
2835 just adjust the stack by leaving the remaining size in
2836 "pretend", handled below. */
2839 /* Save SRP if not a leaf function. */
2840 if (return_address_on_stack)
2842 insn = emit_insn (gen_rtx_SET (VOIDmode,
2843 stack_pointer_rtx,
2844 plus_constant (stack_pointer_rtx,
2845 -4 - pretend)));
2846 pretend = 0;
2847 RTX_FRAME_RELATED_P (insn) = 1;
2849 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2850 set_mem_alias_set (mem, get_frame_alias_set ());
2851 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM));
2852 RTX_FRAME_RELATED_P (insn) = 1;
2853 framesize += 4;
2856 /* Set up the frame pointer, if needed. */
2857 if (frame_pointer_needed)
2859 insn = emit_insn (gen_rtx_SET (VOIDmode,
2860 stack_pointer_rtx,
2861 plus_constant (stack_pointer_rtx,
2862 -4 - pretend)));
2863 pretend = 0;
2864 RTX_FRAME_RELATED_P (insn) = 1;
2866 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2867 set_mem_alias_set (mem, get_frame_alias_set ());
2868 insn = emit_move_insn (mem, frame_pointer_rtx);
2869 RTX_FRAME_RELATED_P (insn) = 1;
2871 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
2872 RTX_FRAME_RELATED_P (insn) = 1;
2874 framesize += 4;
2877 /* Between frame-pointer and saved registers lie the area for local
2878 variables. If we get here with "pretended" size remaining, count
2879 it into the general stack size. */
2880 size += pretend;
2882 /* Get a contiguous sequence of registers, starting with R0, that need
2883 to be saved. */
2884 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
2886 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
2888 n_movem_regs++;
2890 /* Check if movem may be used for registers so far. */
2891 if (regno == last_movem_reg + 1)
2892 /* Yes, update next expected register. */
2893 last_movem_reg = regno;
2894 else
2896 /* We cannot use movem for all registers. We have to flush
2897 any movem:ed registers we got so far. */
2898 if (last_movem_reg != -1)
2900 int n_saved
2901 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2903 /* It is a win to use a side-effect assignment for
2904 64 <= size <= 128. But side-effect on movem was
2905 not usable for CRIS v0..3. Also only do it if
2906 side-effects insns are allowed. */
2907 if ((last_movem_reg + 1) * 4 + size >= 64
2908 && (last_movem_reg + 1) * 4 + size <= 128
2909 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2910 && TARGET_SIDE_EFFECT_PREFIXES)
2913 = gen_rtx_MEM (SImode,
2914 plus_constant (stack_pointer_rtx,
2915 -(n_saved * 4 + size)));
2916 set_mem_alias_set (mem, get_frame_alias_set ());
2917 insn
2918 = cris_emit_movem_store (mem, GEN_INT (n_saved),
2919 -(n_saved * 4 + size),
2920 true);
2922 else
2924 insn
2925 = gen_rtx_SET (VOIDmode,
2926 stack_pointer_rtx,
2927 plus_constant (stack_pointer_rtx,
2928 -(n_saved * 4 + size)));
2929 insn = emit_insn (insn);
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 = cris_emit_movem_store (mem, GEN_INT (n_saved),
2935 0, true);
2938 framesize += n_saved * 4 + size;
2939 last_movem_reg = -1;
2940 size = 0;
2943 insn = emit_insn (gen_rtx_SET (VOIDmode,
2944 stack_pointer_rtx,
2945 plus_constant (stack_pointer_rtx,
2946 -4 - size)));
2947 RTX_FRAME_RELATED_P (insn) = 1;
2949 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2950 set_mem_alias_set (mem, get_frame_alias_set ());
2951 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2952 RTX_FRAME_RELATED_P (insn) = 1;
2954 framesize += 4 + size;
2955 size = 0;
2960 /* Check after, if we could movem all registers. This is the normal case. */
2961 if (last_movem_reg != -1)
2963 int n_saved
2964 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2966 /* Side-effect on movem was not usable for CRIS v0..3. Also only
2967 do it if side-effects insns are allowed. */
2968 if ((last_movem_reg + 1) * 4 + size >= 64
2969 && (last_movem_reg + 1) * 4 + size <= 128
2970 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2971 && TARGET_SIDE_EFFECT_PREFIXES)
2974 = gen_rtx_MEM (SImode,
2975 plus_constant (stack_pointer_rtx,
2976 -(n_saved * 4 + size)));
2977 set_mem_alias_set (mem, get_frame_alias_set ());
2978 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2979 -(n_saved * 4 + size), true);
2981 else
2983 insn
2984 = gen_rtx_SET (VOIDmode,
2985 stack_pointer_rtx,
2986 plus_constant (stack_pointer_rtx,
2987 -(n_saved * 4 + size)));
2988 insn = emit_insn (insn);
2989 RTX_FRAME_RELATED_P (insn) = 1;
2991 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2992 set_mem_alias_set (mem, get_frame_alias_set ());
2993 insn = cris_emit_movem_store (mem, GEN_INT (n_saved), 0, true);
2996 framesize += n_saved * 4 + size;
2997 /* We have to put outgoing argument space after regs. */
2998 if (cfoa_size)
3000 insn = emit_insn (gen_rtx_SET (VOIDmode,
3001 stack_pointer_rtx,
3002 plus_constant (stack_pointer_rtx,
3003 -cfoa_size)));
3004 RTX_FRAME_RELATED_P (insn) = 1;
3005 framesize += cfoa_size;
3008 else if ((size + cfoa_size) > 0)
3010 insn = emit_insn (gen_rtx_SET (VOIDmode,
3011 stack_pointer_rtx,
3012 plus_constant (stack_pointer_rtx,
3013 -(cfoa_size + size))));
3014 RTX_FRAME_RELATED_P (insn) = 1;
3015 framesize += size + cfoa_size;
3018 /* Set up the PIC register, if it is used. */
3019 if (got_really_used)
3021 rtx got
3022 = gen_rtx_UNSPEC (SImode, gen_rtvec (1, const0_rtx), CRIS_UNSPEC_GOT);
3023 emit_move_insn (pic_offset_table_rtx, got);
3025 /* FIXME: This is a cover-up for flow2 messing up; it doesn't
3026 follow exceptional paths and tries to delete the GOT load as
3027 unused, if it isn't used on the non-exceptional paths. Other
3028 ports have similar or other cover-ups, or plain bugs marking
3029 the GOT register load as maybe-dead. To see this, remove the
3030 line below and try libsupc++/vec.cc or a trivial
3031 "static void y (); void x () {try {y ();} catch (...) {}}". */
3032 emit_use (pic_offset_table_rtx);
3035 if (cris_max_stackframe && framesize > cris_max_stackframe)
3036 warning (0, "stackframe too big: %d bytes", framesize);
3039 /* The expander for the epilogue pattern. */
3041 void
3042 cris_expand_epilogue (void)
3044 int regno;
3045 int size = get_frame_size ();
3046 int last_movem_reg = -1;
3047 int argspace_offset = crtl->outgoing_args_size;
3048 int pretend = crtl->args.pretend_args_size;
3049 rtx mem;
3050 bool return_address_on_stack = cris_return_address_on_stack ();
3051 /* A reference may have been optimized out
3052 (like the abort () in fde_split in unwind-dw2-fde.c, at least 3.2.1)
3053 so check that it's still used. */
3054 int got_really_used = false;
3055 int n_movem_regs = 0;
3057 if (!TARGET_PROLOGUE_EPILOGUE)
3058 return;
3060 if (crtl->uses_pic_offset_table)
3062 /* A reference may have been optimized out (like the abort () in
3063 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
3064 it's still used. */
3065 push_topmost_sequence ();
3066 got_really_used
3067 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
3068 pop_topmost_sequence ();
3071 /* Align byte count of stack frame. */
3072 if (TARGET_STACK_ALIGN)
3073 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
3075 /* Check how many saved regs we can movem. They start at r0 and must
3076 be contiguous. */
3077 for (regno = 0;
3078 regno < FIRST_PSEUDO_REGISTER;
3079 regno++)
3080 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3082 n_movem_regs++;
3084 if (regno == last_movem_reg + 1)
3085 last_movem_reg = regno;
3086 else
3087 break;
3090 /* If there was only one register that really needed to be saved
3091 through movem, don't use movem. */
3092 if (n_movem_regs == 1)
3093 last_movem_reg = -1;
3095 /* Now emit "normal" move insns for all regs higher than the movem
3096 regs. */
3097 for (regno = FIRST_PSEUDO_REGISTER - 1;
3098 regno > last_movem_reg;
3099 regno--)
3100 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3102 rtx insn;
3104 if (argspace_offset)
3106 /* There is an area for outgoing parameters located before
3107 the saved registers. We have to adjust for that. */
3108 emit_insn (gen_rtx_SET (VOIDmode,
3109 stack_pointer_rtx,
3110 plus_constant (stack_pointer_rtx,
3111 argspace_offset)));
3112 /* Make sure we only do this once. */
3113 argspace_offset = 0;
3116 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3117 stack_pointer_rtx));
3118 set_mem_alias_set (mem, get_frame_alias_set ());
3119 insn = emit_move_insn (gen_rtx_raw_REG (SImode, regno), mem);
3121 /* Whenever we emit insns with post-incremented addresses
3122 ourselves, we must add a post-inc note manually. */
3123 REG_NOTES (insn)
3124 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3127 /* If we have any movem-restore, do it now. */
3128 if (last_movem_reg != -1)
3130 rtx insn;
3132 if (argspace_offset)
3134 emit_insn (gen_rtx_SET (VOIDmode,
3135 stack_pointer_rtx,
3136 plus_constant (stack_pointer_rtx,
3137 argspace_offset)));
3138 argspace_offset = 0;
3141 mem = gen_rtx_MEM (SImode,
3142 gen_rtx_POST_INC (SImode, stack_pointer_rtx));
3143 set_mem_alias_set (mem, get_frame_alias_set ());
3144 insn
3145 = emit_insn (cris_gen_movem_load (mem,
3146 GEN_INT (last_movem_reg + 1), 0));
3147 /* Whenever we emit insns with post-incremented addresses
3148 ourselves, we must add a post-inc note manually. */
3149 if (side_effects_p (PATTERN (insn)))
3150 REG_NOTES (insn)
3151 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3154 /* If we don't clobber all of the allocated stack area (we've already
3155 deallocated saved registers), GCC might want to schedule loads from
3156 the stack to *after* the stack-pointer restore, which introduces an
3157 interrupt race condition. This happened for the initial-value
3158 SRP-restore for g++.dg/eh/registers1.C (noticed by inspection of
3159 other failure for that test). It also happened for the stack slot
3160 for the return value in (one version of)
3161 linux/fs/dcache.c:__d_lookup, at least with "-O2
3162 -fno-omit-frame-pointer". */
3164 /* Restore frame pointer if necessary. */
3165 if (frame_pointer_needed)
3167 rtx insn;
3169 emit_insn (gen_cris_frame_deallocated_barrier ());
3171 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
3172 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3173 stack_pointer_rtx));
3174 set_mem_alias_set (mem, get_frame_alias_set ());
3175 insn = emit_move_insn (frame_pointer_rtx, mem);
3177 /* Whenever we emit insns with post-incremented addresses
3178 ourselves, we must add a post-inc note manually. */
3179 REG_NOTES (insn)
3180 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3182 else if ((size + argspace_offset) != 0)
3184 emit_insn (gen_cris_frame_deallocated_barrier ());
3186 /* If there was no frame-pointer to restore sp from, we must
3187 explicitly deallocate local variables. */
3189 /* Handle space for outgoing parameters that hasn't been handled
3190 yet. */
3191 size += argspace_offset;
3193 emit_insn (gen_rtx_SET (VOIDmode,
3194 stack_pointer_rtx,
3195 plus_constant (stack_pointer_rtx, size)));
3198 /* If this function has no pushed register parameters
3199 (stdargs/varargs), and if it is not a leaf function, then we have
3200 the return address on the stack. */
3201 if (return_address_on_stack && pretend == 0)
3203 if (TARGET_V32 || crtl->calls_eh_return)
3205 rtx mem;
3206 rtx insn;
3207 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3208 mem = gen_rtx_MEM (SImode,
3209 gen_rtx_POST_INC (SImode,
3210 stack_pointer_rtx));
3211 set_mem_alias_set (mem, get_frame_alias_set ());
3212 insn = emit_move_insn (srpreg, mem);
3214 /* Whenever we emit insns with post-incremented addresses
3215 ourselves, we must add a post-inc note manually. */
3216 REG_NOTES (insn)
3217 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3219 if (crtl->calls_eh_return)
3220 emit_insn (gen_addsi3 (stack_pointer_rtx,
3221 stack_pointer_rtx,
3222 gen_rtx_raw_REG (SImode,
3223 CRIS_STACKADJ_REG)));
3224 cris_expand_return (false);
3226 else
3227 cris_expand_return (true);
3229 return;
3232 /* If we pushed some register parameters, then adjust the stack for
3233 them. */
3234 if (pretend != 0)
3236 /* If SRP is stored on the way, we need to restore it first. */
3237 if (return_address_on_stack)
3239 rtx mem;
3240 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3241 rtx insn;
3243 mem = gen_rtx_MEM (SImode,
3244 gen_rtx_POST_INC (SImode,
3245 stack_pointer_rtx));
3246 set_mem_alias_set (mem, get_frame_alias_set ());
3247 insn = emit_move_insn (srpreg, mem);
3249 /* Whenever we emit insns with post-incremented addresses
3250 ourselves, we must add a post-inc note manually. */
3251 REG_NOTES (insn)
3252 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3255 emit_insn (gen_rtx_SET (VOIDmode,
3256 stack_pointer_rtx,
3257 plus_constant (stack_pointer_rtx, pretend)));
3260 /* Perform the "physical" unwinding that the EH machinery calculated. */
3261 if (crtl->calls_eh_return)
3262 emit_insn (gen_addsi3 (stack_pointer_rtx,
3263 stack_pointer_rtx,
3264 gen_rtx_raw_REG (SImode,
3265 CRIS_STACKADJ_REG)));
3266 cris_expand_return (false);
3269 /* Worker function for generating movem from mem for load_multiple. */
3272 cris_gen_movem_load (rtx src, rtx nregs_rtx, int nprefix)
3274 int nregs = INTVAL (nregs_rtx);
3275 rtvec vec;
3276 int eltno = 1;
3277 int i;
3278 rtx srcreg = XEXP (src, 0);
3279 unsigned int regno = nregs - 1;
3280 int regno_inc = -1;
3282 if (TARGET_V32)
3284 regno = 0;
3285 regno_inc = 1;
3288 if (GET_CODE (srcreg) == POST_INC)
3289 srcreg = XEXP (srcreg, 0);
3291 CRIS_ASSERT (REG_P (srcreg));
3293 /* Don't use movem for just one insn. The insns are equivalent except
3294 for the pipeline hazard (on v32); movem does not forward the loaded
3295 registers so there's a three cycles penalty for their use. */
3296 if (nregs == 1)
3297 return gen_movsi (gen_rtx_REG (SImode, 0), src);
3299 vec = rtvec_alloc (nprefix + nregs
3300 + (GET_CODE (XEXP (src, 0)) == POST_INC));
3302 if (GET_CODE (XEXP (src, 0)) == POST_INC)
3304 RTVEC_ELT (vec, nprefix + 1)
3305 = gen_rtx_SET (VOIDmode, srcreg, plus_constant (srcreg, nregs * 4));
3306 eltno++;
3309 src = replace_equiv_address (src, srcreg);
3310 RTVEC_ELT (vec, nprefix)
3311 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno), src);
3312 regno += regno_inc;
3314 for (i = 1; i < nregs; i++, eltno++)
3316 RTVEC_ELT (vec, nprefix + eltno)
3317 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno),
3318 adjust_address_nv (src, SImode, i * 4));
3319 regno += regno_inc;
3322 return gen_rtx_PARALLEL (VOIDmode, vec);
3325 /* Worker function for generating movem to mem. If FRAME_RELATED, notes
3326 are added that the dwarf2 machinery understands. */
3329 cris_emit_movem_store (rtx dest, rtx nregs_rtx, int increment,
3330 bool frame_related)
3332 int nregs = INTVAL (nregs_rtx);
3333 rtvec vec;
3334 int eltno = 1;
3335 int i;
3336 rtx insn;
3337 rtx destreg = XEXP (dest, 0);
3338 unsigned int regno = nregs - 1;
3339 int regno_inc = -1;
3341 if (TARGET_V32)
3343 regno = 0;
3344 regno_inc = 1;
3347 if (GET_CODE (destreg) == POST_INC)
3348 increment += nregs * 4;
3350 if (GET_CODE (destreg) == POST_INC || GET_CODE (destreg) == PLUS)
3351 destreg = XEXP (destreg, 0);
3353 CRIS_ASSERT (REG_P (destreg));
3355 /* Don't use movem for just one insn. The insns are equivalent except
3356 for the pipeline hazard (on v32); movem does not forward the loaded
3357 registers so there's a three cycles penalty for use. */
3358 if (nregs == 1)
3360 rtx mov = gen_rtx_SET (VOIDmode, dest, gen_rtx_REG (SImode, 0));
3362 if (increment == 0)
3364 insn = emit_insn (mov);
3365 if (frame_related)
3366 RTX_FRAME_RELATED_P (insn) = 1;
3367 return insn;
3370 /* If there was a request for a side-effect, create the ordinary
3371 parallel. */
3372 vec = rtvec_alloc (2);
3374 RTVEC_ELT (vec, 0) = mov;
3375 RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, destreg,
3376 plus_constant (destreg, increment));
3377 if (frame_related)
3379 RTX_FRAME_RELATED_P (mov) = 1;
3380 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3383 else
3385 vec = rtvec_alloc (nregs + (increment != 0 ? 1 : 0));
3386 RTVEC_ELT (vec, 0)
3387 = gen_rtx_SET (VOIDmode,
3388 replace_equiv_address (dest,
3389 plus_constant (destreg,
3390 increment)),
3391 gen_rtx_REG (SImode, regno));
3392 regno += regno_inc;
3394 /* The dwarf2 info wants this mark on each component in a parallel
3395 that's part of the prologue (though it's optional on the first
3396 component). */
3397 if (frame_related)
3398 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 0)) = 1;
3400 if (increment != 0)
3402 RTVEC_ELT (vec, 1)
3403 = gen_rtx_SET (VOIDmode, destreg,
3404 plus_constant (destreg,
3405 increment != 0
3406 ? increment : nregs * 4));
3407 eltno++;
3409 if (frame_related)
3410 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3412 /* Don't call adjust_address_nv on a post-incremented address if
3413 we can help it. */
3414 if (GET_CODE (XEXP (dest, 0)) == POST_INC)
3415 dest = replace_equiv_address (dest, destreg);
3418 for (i = 1; i < nregs; i++, eltno++)
3420 RTVEC_ELT (vec, eltno)
3421 = gen_rtx_SET (VOIDmode, adjust_address_nv (dest, SImode, i * 4),
3422 gen_rtx_REG (SImode, regno));
3423 if (frame_related)
3424 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, eltno)) = 1;
3425 regno += regno_inc;
3429 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, vec));
3431 /* Because dwarf2out.c handles the insns in a parallel as a sequence,
3432 we need to keep the stack adjustment separate, after the
3433 MEM-setters. Else the stack-adjustment in the second component of
3434 the parallel would be mishandled; the offsets for the SETs that
3435 follow it would be wrong. We prepare for this by adding a
3436 REG_FRAME_RELATED_EXPR with the MEM-setting parts in a SEQUENCE
3437 followed by the increment. Note that we have FRAME_RELATED_P on
3438 all the SETs, including the original stack adjustment SET in the
3439 parallel. */
3440 if (frame_related)
3442 if (increment != 0)
3444 rtx seq = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nregs + 1));
3445 XVECEXP (seq, 0, 0) = copy_rtx (XVECEXP (PATTERN (insn), 0, 0));
3446 for (i = 1; i < nregs; i++)
3447 XVECEXP (seq, 0, i)
3448 = copy_rtx (XVECEXP (PATTERN (insn), 0, i + 1));
3449 XVECEXP (seq, 0, nregs) = copy_rtx (XVECEXP (PATTERN (insn), 0, 1));
3450 add_reg_note (insn, REG_FRAME_RELATED_EXPR, seq);
3453 RTX_FRAME_RELATED_P (insn) = 1;
3456 return insn;
3459 /* Worker function for expanding the address for PIC function calls. */
3461 void
3462 cris_expand_pic_call_address (rtx *opp)
3464 rtx op = *opp;
3466 gcc_assert (MEM_P (op));
3467 op = XEXP (op, 0);
3469 /* It might be that code can be generated that jumps to 0 (or to a
3470 specific address). Don't die on that. (There is a
3471 testcase.) */
3472 if (CONSTANT_ADDRESS_P (op) && !CONST_INT_P (op))
3474 enum cris_pic_symbol_type t = cris_pic_symbol_type_of (op);
3476 CRIS_ASSERT (can_create_pseudo_p ());
3478 /* For local symbols (non-PLT), just get the plain symbol
3479 reference into a register. For symbols that can be PLT, make
3480 them PLT. */
3481 if (t == cris_rel_symbol)
3483 /* For v32, we're fine as-is; just PICify the symbol. Forcing
3484 into a register caused performance regression for 3.2.1,
3485 observable in __floatdidf and elsewhere in libgcc. */
3486 if (TARGET_V32)
3488 rtx sym = GET_CODE (op) != CONST ? op : get_related_value (op);
3489 HOST_WIDE_INT offs = get_integer_term (op);
3491 /* We can't get calls to sym+N, N integer, can we? */
3492 gcc_assert (offs == 0);
3494 op = gen_rtx_CONST (Pmode,
3495 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, sym),
3496 CRIS_UNSPEC_PCREL));
3498 else
3499 op = force_reg (Pmode, op);
3501 else if (t == cris_got_symbol)
3503 if (TARGET_AVOID_GOTPLT)
3505 /* Change a "jsr sym" into (allocate register rM, rO)
3506 "move.d (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_GOTREL)),rM"
3507 "add.d rPIC,rM,rO", "jsr rO" for pre-v32 and
3508 "jsr (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_PCREL))"
3509 for v32. */
3510 rtx tem, rm, ro;
3511 gcc_assert (can_create_pseudo_p ());
3512 crtl->uses_pic_offset_table = 1;
3513 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3514 TARGET_V32
3515 ? CRIS_UNSPEC_PLT_PCREL
3516 : CRIS_UNSPEC_PLT_GOTREL);
3517 tem = gen_rtx_CONST (Pmode, tem);
3518 if (TARGET_V32)
3519 op = tem;
3520 else
3522 rm = gen_reg_rtx (Pmode);
3523 emit_move_insn (rm, tem);
3524 ro = gen_reg_rtx (Pmode);
3525 if (expand_binop (Pmode, add_optab, rm,
3526 pic_offset_table_rtx,
3527 ro, 0, OPTAB_LIB_WIDEN) != ro)
3528 internal_error ("expand_binop failed in movsi got");
3529 op = ro;
3532 else
3534 /* Change a "jsr sym" into (allocate register rM, rO)
3535 "move.d (const (unspec [sym] CRIS_UNSPEC_PLTGOTREAD)),rM"
3536 "add.d rPIC,rM,rO" "jsr [rO]" with the memory access
3537 marked as not trapping and not aliasing. No "move.d
3538 [rO],rP" as that would invite to re-use of a value
3539 that should not be reused. FIXME: Need a peephole2
3540 for cases when this is cse:d from the call, to change
3541 back to just get the PLT entry address, so we don't
3542 resolve the same symbol over and over (the memory
3543 access of the PLTGOT isn't constant). */
3544 rtx tem, mem, rm, ro;
3546 gcc_assert (can_create_pseudo_p ());
3547 crtl->uses_pic_offset_table = 1;
3548 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3549 CRIS_UNSPEC_PLTGOTREAD);
3550 rm = gen_reg_rtx (Pmode);
3551 emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
3552 ro = gen_reg_rtx (Pmode);
3553 if (expand_binop (Pmode, add_optab, rm,
3554 pic_offset_table_rtx,
3555 ro, 0, OPTAB_LIB_WIDEN) != ro)
3556 internal_error ("expand_binop failed in movsi got");
3557 mem = gen_rtx_MEM (Pmode, ro);
3559 /* This MEM doesn't alias anything. Whether it aliases
3560 other same symbols is unimportant. */
3561 set_mem_alias_set (mem, new_alias_set ());
3562 MEM_NOTRAP_P (mem) = 1;
3563 op = mem;
3566 else
3567 /* Can't possibly get a GOT-needing-fixup for a function-call,
3568 right? */
3569 fatal_insn ("unidentifiable call op", op);
3571 *opp = replace_equiv_address (*opp, op);
3575 /* Make sure operands are in the right order for an addsi3 insn as
3576 generated by a define_split. Nothing but REG_P as the first
3577 operand is recognized by addsi3 after reload. OPERANDS contains
3578 the operands, with the first at OPERANDS[N] and the second at
3579 OPERANDS[N+1]. */
3581 void
3582 cris_order_for_addsi3 (rtx *operands, int n)
3584 if (!REG_P (operands[n]))
3586 rtx tem = operands[n];
3587 operands[n] = operands[n + 1];
3588 operands[n + 1] = tem;
3592 /* Use from within code, from e.g. PRINT_OPERAND and
3593 PRINT_OPERAND_ADDRESS. Macros used in output_addr_const need to emit
3594 different things depending on whether code operand or constant is
3595 emitted. */
3597 static void
3598 cris_output_addr_const (FILE *file, rtx x)
3600 in_code++;
3601 output_addr_const (file, x);
3602 in_code--;
3605 /* Worker function for ASM_OUTPUT_SYMBOL_REF. */
3607 void
3608 cris_asm_output_symbol_ref (FILE *file, rtx x)
3610 gcc_assert (GET_CODE (x) == SYMBOL_REF);
3612 if (flag_pic && in_code > 0)
3614 const char *origstr = XSTR (x, 0);
3615 const char *str;
3616 str = (* targetm.strip_name_encoding) (origstr);
3617 assemble_name (file, str);
3619 /* Sanity check. */
3620 if (!TARGET_V32 && !crtl->uses_pic_offset_table)
3621 output_operand_lossage ("PIC register isn't set up");
3623 else
3624 assemble_name (file, XSTR (x, 0));
3627 /* Worker function for ASM_OUTPUT_LABEL_REF. */
3629 void
3630 cris_asm_output_label_ref (FILE *file, char *buf)
3632 if (flag_pic && in_code > 0)
3634 assemble_name (file, buf);
3636 /* Sanity check. */
3637 if (!TARGET_V32 && !crtl->uses_pic_offset_table)
3638 internal_error ("emitting PIC operand, but PIC register "
3639 "isn%'t set up");
3641 else
3642 assemble_name (file, buf);
3645 /* Worker function for TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */
3647 static bool
3648 cris_output_addr_const_extra (FILE *file, rtx xconst)
3650 switch (GET_CODE (xconst))
3652 rtx x;
3654 case UNSPEC:
3655 x = XVECEXP (xconst, 0, 0);
3656 CRIS_ASSERT (GET_CODE (x) == SYMBOL_REF
3657 || GET_CODE (x) == LABEL_REF
3658 || GET_CODE (x) == CONST);
3659 output_addr_const (file, x);
3660 switch (XINT (xconst, 1))
3662 case CRIS_UNSPEC_PCREL:
3663 /* We only get this with -fpic/PIC to tell it apart from an
3664 invalid symbol. We can't tell here, but it should only
3665 be the operand of a call or movsi. */
3666 gcc_assert (TARGET_V32 && flag_pic);
3667 break;
3669 case CRIS_UNSPEC_PLT_PCREL:
3670 gcc_assert (TARGET_V32);
3671 fprintf (file, ":PLT");
3672 break;
3674 case CRIS_UNSPEC_PLT_GOTREL:
3675 gcc_assert (!TARGET_V32);
3676 fprintf (file, ":PLTG");
3677 break;
3679 case CRIS_UNSPEC_GOTREL:
3680 gcc_assert (!TARGET_V32);
3681 fprintf (file, ":GOTOFF");
3682 break;
3684 case CRIS_UNSPEC_GOTREAD:
3685 if (flag_pic == 1)
3686 fprintf (file, ":GOT16");
3687 else
3688 fprintf (file, ":GOT");
3689 break;
3691 case CRIS_UNSPEC_PLTGOTREAD:
3692 if (flag_pic == 1)
3693 fprintf (file, CRIS_GOTPLT_SUFFIX "16");
3694 else
3695 fprintf (file, CRIS_GOTPLT_SUFFIX);
3696 break;
3698 default:
3699 gcc_unreachable ();
3701 return true;
3703 default:
3704 return false;
3708 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3710 static rtx
3711 cris_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3712 int incoming ATTRIBUTE_UNUSED)
3714 return gen_rtx_REG (Pmode, CRIS_STRUCT_VALUE_REGNUM);
3717 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3719 static void
3720 cris_setup_incoming_varargs (cumulative_args_t ca_v,
3721 enum machine_mode mode ATTRIBUTE_UNUSED,
3722 tree type ATTRIBUTE_UNUSED,
3723 int *pretend_arg_size,
3724 int second_time)
3726 CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v);
3728 if (ca->regs < CRIS_MAX_ARGS_IN_REGS)
3730 int stdarg_regs = CRIS_MAX_ARGS_IN_REGS - ca->regs;
3731 cfun->machine->stdarg_regs = stdarg_regs;
3732 *pretend_arg_size = stdarg_regs * 4;
3735 if (TARGET_PDEBUG)
3736 fprintf (asm_out_file,
3737 "\n; VA:: ANSI: %d args before, anon @ #%d, %dtime\n",
3738 ca->regs, *pretend_arg_size, second_time);
3741 /* Return true if TYPE must be passed by invisible reference.
3742 For cris, we pass <= 8 bytes by value, others by reference. */
3744 static bool
3745 cris_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED,
3746 enum machine_mode mode, const_tree type,
3747 bool named ATTRIBUTE_UNUSED)
3749 return (targetm.calls.must_pass_in_stack (mode, type)
3750 || CRIS_FUNCTION_ARG_SIZE (mode, type) > 8);
3753 /* A combination of defining TARGET_PROMOTE_FUNCTION_MODE, promoting arguments
3754 and *not* defining TARGET_PROMOTE_PROTOTYPES or PROMOTE_MODE gives the
3755 best code size and speed for gcc, ipps and products in gcc-2.7.2. */
3757 enum machine_mode
3758 cris_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
3759 enum machine_mode mode,
3760 int *punsignedp ATTRIBUTE_UNUSED,
3761 const_tree fntype ATTRIBUTE_UNUSED,
3762 int for_return)
3764 /* Defining PROMOTE_FUNCTION_RETURN in gcc-2.7.2 uncovered bug 981110 (even
3765 when modifying TARGET_FUNCTION_VALUE to return the promoted mode).
3766 Maybe pointless as of now, but let's keep the old behavior. */
3767 if (for_return == 1)
3768 return mode;
3769 return CRIS_PROMOTED_MODE (mode, *punsignedp, type);
3772 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
3773 time being. */
3775 static rtx
3776 cris_function_value(const_tree type,
3777 const_tree func ATTRIBUTE_UNUSED,
3778 bool outgoing ATTRIBUTE_UNUSED)
3780 return gen_rtx_REG (TYPE_MODE (type), CRIS_FIRST_ARG_REG);
3783 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
3784 time being. */
3786 static rtx
3787 cris_libcall_value (enum machine_mode mode,
3788 const_rtx fun ATTRIBUTE_UNUSED)
3790 return gen_rtx_REG (mode, CRIS_FIRST_ARG_REG);
3793 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
3794 time being. */
3796 bool
3797 cris_function_value_regno_p (const unsigned int regno)
3799 return (regno == CRIS_FIRST_ARG_REG);
3802 static int
3803 cris_arg_partial_bytes (cumulative_args_t ca, enum machine_mode mode,
3804 tree type, bool named ATTRIBUTE_UNUSED)
3806 if (get_cumulative_args (ca)->regs == CRIS_MAX_ARGS_IN_REGS - 1
3807 && !targetm.calls.must_pass_in_stack (mode, type)
3808 && CRIS_FUNCTION_ARG_SIZE (mode, type) > 4
3809 && CRIS_FUNCTION_ARG_SIZE (mode, type) <= 8)
3810 return UNITS_PER_WORD;
3811 else
3812 return 0;
3815 static rtx
3816 cris_function_arg_1 (cumulative_args_t ca_v,
3817 enum machine_mode mode ATTRIBUTE_UNUSED,
3818 const_tree type ATTRIBUTE_UNUSED,
3819 bool named, bool incoming)
3821 const CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v);
3823 if ((!incoming || named) && ca->regs < CRIS_MAX_ARGS_IN_REGS)
3824 return gen_rtx_REG (mode, CRIS_FIRST_ARG_REG + ca->regs);
3825 else
3826 return NULL_RTX;
3829 /* Worker function for TARGET_FUNCTION_ARG.
3830 The void_type_node is sent as a "closing" call. */
3832 static rtx
3833 cris_function_arg (cumulative_args_t ca, enum machine_mode mode,
3834 const_tree type, bool named)
3836 return cris_function_arg_1 (ca, mode, type, named, false);
3839 /* Worker function for TARGET_FUNCTION_INCOMING_ARG.
3841 The differences between this and the previous, is that this one checks
3842 that an argument is named, since incoming stdarg/varargs arguments are
3843 pushed onto the stack, and we don't have to check against the "closing"
3844 void_type_node TYPE parameter. */
3846 static rtx
3847 cris_function_incoming_arg (cumulative_args_t ca, enum machine_mode mode,
3848 const_tree type, bool named)
3850 return cris_function_arg_1 (ca, mode, type, named, true);
3853 /* Worker function for TARGET_FUNCTION_ARG_ADVANCE. */
3855 static void
3856 cris_function_arg_advance (cumulative_args_t ca_v, enum machine_mode mode,
3857 const_tree type, bool named ATTRIBUTE_UNUSED)
3859 CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v);
3861 ca->regs += (3 + CRIS_FUNCTION_ARG_SIZE (mode, type)) / 4;
3864 /* Worker function for TARGET_MD_ASM_CLOBBERS. */
3866 static tree
3867 cris_md_asm_clobbers (tree outputs, tree inputs, tree in_clobbers)
3869 HARD_REG_SET mof_set;
3870 tree clobbers;
3871 tree t;
3873 CLEAR_HARD_REG_SET (mof_set);
3874 SET_HARD_REG_BIT (mof_set, CRIS_MOF_REGNUM);
3876 /* For the time being, all asms clobber condition codes. Revisit when
3877 there's a reasonable use for inputs/outputs that mention condition
3878 codes. */
3879 clobbers
3880 = tree_cons (NULL_TREE,
3881 build_string (strlen (reg_names[CRIS_CC0_REGNUM]),
3882 reg_names[CRIS_CC0_REGNUM]),
3883 in_clobbers);
3885 for (t = outputs; t != NULL; t = TREE_CHAIN (t))
3887 tree val = TREE_VALUE (t);
3889 /* The constraint letter for the singleton register class of MOF
3890 is 'h'. If it's mentioned in the constraints, the asm is
3891 MOF-aware and adding it to the clobbers would cause it to have
3892 impossible constraints. */
3893 if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
3894 'h') != NULL
3895 || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
3896 return clobbers;
3899 for (t = inputs; t != NULL; t = TREE_CHAIN (t))
3901 tree val = TREE_VALUE (t);
3903 if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
3904 'h') != NULL
3905 || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
3906 return clobbers;
3909 return tree_cons (NULL_TREE,
3910 build_string (strlen (reg_names[CRIS_MOF_REGNUM]),
3911 reg_names[CRIS_MOF_REGNUM]),
3912 clobbers);
3915 /* Implement TARGET_FRAME_POINTER_REQUIRED.
3917 Really only needed if the stack frame has variable length (alloca
3918 or variable sized local arguments (GNU C extension). See PR39499 and
3919 PR38609 for the reason this isn't just 0. */
3921 bool
3922 cris_frame_pointer_required (void)
3924 return !current_function_sp_is_unchanging;
3927 /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
3929 This looks too complicated, and it is. I assigned r7 to be the
3930 static chain register, but it is call-saved, so we have to save it,
3931 and come back to restore it after the call, so we have to save srp...
3932 Anyway, trampolines are rare enough that we can cope with this
3933 somewhat lack of elegance.
3934 (Do not be tempted to "straighten up" whitespace in the asms; the
3935 assembler #NO_APP state mandates strict spacing). */
3936 /* ??? See the i386 regparm=3 implementation that pushes the static
3937 chain value to the stack in the trampoline, and uses a call-saved
3938 register when called directly. */
3940 static void
3941 cris_asm_trampoline_template (FILE *f)
3943 if (TARGET_V32)
3945 /* This normally-unused nop insn acts as an instruction to
3946 the simulator to flush its instruction cache. None of
3947 the other instructions in the trampoline template suits
3948 as a trigger for V32. The pc-relative addressing mode
3949 works nicely as a trigger for V10.
3950 FIXME: Have specific V32 template (possibly avoiding the
3951 use of a special instruction). */
3952 fprintf (f, "\tclearf x\n");
3953 /* We have to use a register as an intermediate, choosing
3954 semi-randomly R1 (which has to not be the STATIC_CHAIN_REGNUM),
3955 so we can use it for address indirection and jsr target. */
3956 fprintf (f, "\tmove $r1,$mof\n");
3957 /* +4 */
3958 fprintf (f, "\tmove.d 0,$r1\n");
3959 fprintf (f, "\tmove.d $%s,[$r1]\n", reg_names[STATIC_CHAIN_REGNUM]);
3960 fprintf (f, "\taddq 6,$r1\n");
3961 fprintf (f, "\tmove $mof,[$r1]\n");
3962 fprintf (f, "\taddq 6,$r1\n");
3963 fprintf (f, "\tmove $srp,[$r1]\n");
3964 /* +20 */
3965 fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
3966 /* +26 */
3967 fprintf (f, "\tmove.d 0,$r1\n");
3968 fprintf (f, "\tjsr $r1\n");
3969 fprintf (f, "\tsetf\n");
3970 /* +36 */
3971 fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
3972 /* +42 */
3973 fprintf (f, "\tmove.d 0,$r1\n");
3974 /* +48 */
3975 fprintf (f, "\tmove.d 0,$r9\n");
3976 fprintf (f, "\tjump $r9\n");
3977 fprintf (f, "\tsetf\n");
3979 else
3981 fprintf (f, "\tmove.d $%s,[$pc+20]\n", reg_names[STATIC_CHAIN_REGNUM]);
3982 fprintf (f, "\tmove $srp,[$pc+22]\n");
3983 fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
3984 fprintf (f, "\tjsr 0\n");
3985 fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
3986 fprintf (f, "\tjump 0\n");
3990 /* Implement TARGET_TRAMPOLINE_INIT. */
3992 static void
3993 cris_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
3995 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
3996 rtx tramp = XEXP (m_tramp, 0);
3997 rtx mem;
3999 emit_block_move (m_tramp, assemble_trampoline_template (),
4000 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
4002 if (TARGET_V32)
4004 mem = adjust_address (m_tramp, SImode, 6);
4005 emit_move_insn (mem, plus_constant (tramp, 38));
4006 mem = adjust_address (m_tramp, SImode, 22);
4007 emit_move_insn (mem, chain_value);
4008 mem = adjust_address (m_tramp, SImode, 28);
4009 emit_move_insn (mem, fnaddr);
4011 else
4013 mem = adjust_address (m_tramp, SImode, 10);
4014 emit_move_insn (mem, chain_value);
4015 mem = adjust_address (m_tramp, SImode, 16);
4016 emit_move_insn (mem, fnaddr);
4019 /* Note that there is no need to do anything with the cache for
4020 sake of a trampoline. */
4024 #if 0
4025 /* Various small functions to replace macros. Only called from a
4026 debugger. They might collide with gcc functions or system functions,
4027 so only emit them when '#if 1' above. */
4029 enum rtx_code Get_code (rtx);
4031 enum rtx_code
4032 Get_code (rtx x)
4034 return GET_CODE (x);
4037 const char *Get_mode (rtx);
4039 const char *
4040 Get_mode (rtx x)
4042 return GET_MODE_NAME (GET_MODE (x));
4045 rtx Xexp (rtx, int);
4048 Xexp (rtx x, int n)
4050 return XEXP (x, n);
4053 rtx Xvecexp (rtx, int, int);
4056 Xvecexp (rtx x, int n, int m)
4058 return XVECEXP (x, n, m);
4061 int Get_rtx_len (rtx);
4064 Get_rtx_len (rtx x)
4066 return GET_RTX_LENGTH (GET_CODE (x));
4069 /* Use upper-case to distinguish from local variables that are sometimes
4070 called next_insn and prev_insn. */
4072 rtx Next_insn (rtx);
4075 Next_insn (rtx insn)
4077 return NEXT_INSN (insn);
4080 rtx Prev_insn (rtx);
4083 Prev_insn (rtx insn)
4085 return PREV_INSN (insn);
4087 #endif
4089 #include "gt-cris.h"
4092 * Local variables:
4093 * eval: (c-set-style "gnu")
4094 * indent-tabs-mode: t
4095 * End: