Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / config / cris / cris.c
blobba572eb82db864a2872fb9ef519b8954e4431598
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 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 "real.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "tree.h"
35 #include "expr.h"
36 #include "except.h"
37 #include "function.h"
38 #include "toplev.h"
39 #include "recog.h"
40 #include "reload.h"
41 #include "tm_p.h"
42 #include "debug.h"
43 #include "output.h"
44 #include "target.h"
45 #include "target-def.h"
46 #include "ggc.h"
47 #include "optabs.h"
48 #include "df.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 machine_function GTY(())
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 void cris_print_base (rtx, FILE *);
90 static void cris_print_index (rtx, FILE *);
92 static void cris_output_addr_const (FILE *, rtx);
94 static struct machine_function * cris_init_machine_status (void);
96 static rtx cris_struct_value_rtx (tree, int);
98 static void cris_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
99 tree type, int *, int);
101 static int cris_initial_frame_pointer_offset (void);
103 static int saved_regs_mentioned (rtx);
105 static void cris_operand_lossage (const char *, rtx);
107 static int cris_reg_saved_in_regsave_area (unsigned int, bool);
109 static void cris_asm_output_mi_thunk
110 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
112 static void cris_file_start (void);
113 static void cris_init_libfuncs (void);
115 static bool cris_rtx_costs (rtx, int, int, int *);
116 static int cris_address_cost (rtx);
117 static bool cris_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
118 const_tree, bool);
119 static int cris_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
120 tree, bool);
121 static tree cris_md_asm_clobbers (tree, tree, tree);
123 static bool cris_handle_option (size_t, const char *, int);
125 /* This is the parsed result of the "-max-stack-stackframe=" option. If
126 it (still) is zero, then there was no such option given. */
127 int cris_max_stackframe = 0;
129 /* This is the parsed result of the "-march=" option, if given. */
130 int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
132 #undef TARGET_ASM_ALIGNED_HI_OP
133 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
134 #undef TARGET_ASM_ALIGNED_SI_OP
135 #define TARGET_ASM_ALIGNED_SI_OP "\t.dword\t"
136 #undef TARGET_ASM_ALIGNED_DI_OP
137 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
139 /* We need to define these, since the 2byte, 4byte, 8byte op:s are only
140 available in ELF. These "normal" pseudos do not have any alignment
141 constraints or side-effects. */
142 #undef TARGET_ASM_UNALIGNED_HI_OP
143 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
145 #undef TARGET_ASM_UNALIGNED_SI_OP
146 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
148 #undef TARGET_ASM_UNALIGNED_DI_OP
149 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
151 #undef TARGET_ASM_OUTPUT_MI_THUNK
152 #define TARGET_ASM_OUTPUT_MI_THUNK cris_asm_output_mi_thunk
153 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
154 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
156 #undef TARGET_ASM_FILE_START
157 #define TARGET_ASM_FILE_START cris_file_start
159 #undef TARGET_INIT_LIBFUNCS
160 #define TARGET_INIT_LIBFUNCS cris_init_libfuncs
162 #undef TARGET_RTX_COSTS
163 #define TARGET_RTX_COSTS cris_rtx_costs
164 #undef TARGET_ADDRESS_COST
165 #define TARGET_ADDRESS_COST cris_address_cost
167 #undef TARGET_PROMOTE_FUNCTION_ARGS
168 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_const_tree_true
169 #undef TARGET_STRUCT_VALUE_RTX
170 #define TARGET_STRUCT_VALUE_RTX cris_struct_value_rtx
171 #undef TARGET_SETUP_INCOMING_VARARGS
172 #define TARGET_SETUP_INCOMING_VARARGS cris_setup_incoming_varargs
173 #undef TARGET_PASS_BY_REFERENCE
174 #define TARGET_PASS_BY_REFERENCE cris_pass_by_reference
175 #undef TARGET_ARG_PARTIAL_BYTES
176 #define TARGET_ARG_PARTIAL_BYTES cris_arg_partial_bytes
177 #undef TARGET_MD_ASM_CLOBBERS
178 #define TARGET_MD_ASM_CLOBBERS cris_md_asm_clobbers
179 #undef TARGET_DEFAULT_TARGET_FLAGS
180 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | CRIS_SUBTARGET_DEFAULT)
181 #undef TARGET_HANDLE_OPTION
182 #define TARGET_HANDLE_OPTION cris_handle_option
184 struct gcc_target targetm = TARGET_INITIALIZER;
186 /* Helper for cris_load_multiple_op and cris_ret_movem_op. */
188 bool
189 cris_movem_load_rest_p (rtx op, int offs)
191 unsigned int reg_count = XVECLEN (op, 0) - offs;
192 rtx src_addr;
193 int i;
194 rtx elt;
195 int setno;
196 int regno_dir = 1;
197 unsigned int regno = 0;
199 /* Perform a quick check so we don't blow up below. FIXME: Adjust for
200 other than (MEM reg). */
201 if (reg_count <= 1
202 || GET_CODE (XVECEXP (op, 0, offs)) != SET
203 || !REG_P (SET_DEST (XVECEXP (op, 0, offs)))
204 || !MEM_P (SET_SRC (XVECEXP (op, 0, offs))))
205 return false;
207 /* Check a possible post-inc indicator. */
208 if (GET_CODE (SET_SRC (XVECEXP (op, 0, offs + 1))) == PLUS)
210 rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, offs + 1)), 0);
211 rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, offs + 1)), 1);
213 reg_count--;
215 if (reg_count == 1
216 || !REG_P (reg)
217 || !REG_P (SET_DEST (XVECEXP (op, 0, offs + 1)))
218 || REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, offs + 1)))
219 || !CONST_INT_P (inc)
220 || INTVAL (inc) != (HOST_WIDE_INT) reg_count * 4)
221 return false;
222 i = offs + 2;
224 else
225 i = offs + 1;
227 if (!TARGET_V32)
229 regno_dir = -1;
230 regno = reg_count - 1;
233 elt = XVECEXP (op, 0, offs);
234 src_addr = XEXP (SET_SRC (elt), 0);
236 if (GET_CODE (elt) != SET
237 || !REG_P (SET_DEST (elt))
238 || GET_MODE (SET_DEST (elt)) != SImode
239 || REGNO (SET_DEST (elt)) != regno
240 || !MEM_P (SET_SRC (elt))
241 || GET_MODE (SET_SRC (elt)) != SImode
242 || !memory_address_p (SImode, src_addr))
243 return false;
245 for (setno = 1; i < XVECLEN (op, 0); setno++, i++)
247 rtx elt = XVECEXP (op, 0, i);
248 regno += regno_dir;
250 if (GET_CODE (elt) != SET
251 || !REG_P (SET_DEST (elt))
252 || GET_MODE (SET_DEST (elt)) != SImode
253 || REGNO (SET_DEST (elt)) != regno
254 || !MEM_P (SET_SRC (elt))
255 || GET_MODE (SET_SRC (elt)) != SImode
256 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
257 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
258 || !CONST_INT_P (XEXP (XEXP (SET_SRC (elt), 0), 1))
259 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != setno * 4)
260 return false;
263 return true;
266 /* Worker function for predicate for the parallel contents in a movem
267 to-memory. */
269 bool
270 cris_store_multiple_op_p (rtx op)
272 int reg_count = XVECLEN (op, 0);
273 rtx dest;
274 rtx dest_addr;
275 rtx dest_base;
276 int i;
277 rtx elt;
278 int setno;
279 int regno_dir = 1;
280 int regno = 0;
281 int offset = 0;
283 /* Perform a quick check so we don't blow up below. FIXME: Adjust for
284 other than (MEM reg) and (MEM (PLUS reg const)). */
285 if (reg_count <= 1)
286 return false;
288 elt = XVECEXP (op, 0, 0);
290 if (GET_CODE (elt) != SET)
291 return false;
293 dest = SET_DEST (elt);
295 if (!REG_P (SET_SRC (elt)) || !MEM_P (dest))
296 return false;
298 dest_addr = XEXP (dest, 0);
300 /* Check a possible post-inc indicator. */
301 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS)
303 rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 0);
304 rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1);
306 reg_count--;
308 if (reg_count == 1
309 || !REG_P (reg)
310 || !REG_P (SET_DEST (XVECEXP (op, 0, 1)))
311 || REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, 1)))
312 || !CONST_INT_P (inc)
313 /* Support increment by number of registers, and by the offset
314 of the destination, if it has the form (MEM (PLUS reg
315 offset)). */
316 || !((REG_P (dest_addr)
317 && REGNO (dest_addr) == REGNO (reg)
318 && INTVAL (inc) == (HOST_WIDE_INT) reg_count * 4)
319 || (GET_CODE (dest_addr) == PLUS
320 && REG_P (XEXP (dest_addr, 0))
321 && REGNO (XEXP (dest_addr, 0)) == REGNO (reg)
322 && CONST_INT_P (XEXP (dest_addr, 1))
323 && INTVAL (XEXP (dest_addr, 1)) == INTVAL (inc))))
324 return false;
326 i = 2;
328 else
329 i = 1;
331 if (!TARGET_V32)
333 regno_dir = -1;
334 regno = reg_count - 1;
337 if (GET_CODE (elt) != SET
338 || !REG_P (SET_SRC (elt))
339 || GET_MODE (SET_SRC (elt)) != SImode
340 || REGNO (SET_SRC (elt)) != (unsigned int) regno
341 || !MEM_P (SET_DEST (elt))
342 || GET_MODE (SET_DEST (elt)) != SImode)
343 return false;
345 if (REG_P (dest_addr))
347 dest_base = dest_addr;
348 offset = 0;
350 else if (GET_CODE (dest_addr) == PLUS
351 && REG_P (XEXP (dest_addr, 0))
352 && CONST_INT_P (XEXP (dest_addr, 1)))
354 dest_base = XEXP (dest_addr, 0);
355 offset = INTVAL (XEXP (dest_addr, 1));
357 else
358 return false;
360 for (setno = 1; i < XVECLEN (op, 0); setno++, i++)
362 rtx elt = XVECEXP (op, 0, i);
363 regno += regno_dir;
365 if (GET_CODE (elt) != SET
366 || !REG_P (SET_SRC (elt))
367 || GET_MODE (SET_SRC (elt)) != SImode
368 || REGNO (SET_SRC (elt)) != (unsigned int) regno
369 || !MEM_P (SET_DEST (elt))
370 || GET_MODE (SET_DEST (elt)) != SImode
371 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
372 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_base)
373 || !CONST_INT_P (XEXP (XEXP (SET_DEST (elt), 0), 1))
374 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != setno * 4 + offset)
375 return false;
378 return true;
381 /* The CONDITIONAL_REGISTER_USAGE worker. */
383 void
384 cris_conditional_register_usage (void)
386 /* FIXME: This isn't nice. We should be able to use that register for
387 something else if the PIC table isn't needed. */
388 if (flag_pic)
389 fixed_regs[PIC_OFFSET_TABLE_REGNUM]
390 = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
392 /* Allow use of ACR (PC in pre-V32) and tweak order. */
393 if (TARGET_V32)
395 static const int reg_alloc_order_v32[] = REG_ALLOC_ORDER_V32;
396 unsigned int i;
398 fixed_regs[CRIS_ACR_REGNUM] = 0;
400 for (i = 0;
401 i < sizeof (reg_alloc_order_v32)/sizeof (reg_alloc_order_v32[0]);
402 i++)
403 reg_alloc_order[i] = reg_alloc_order_v32[i];
406 if (TARGET_HAS_MUL_INSNS)
407 fixed_regs[CRIS_MOF_REGNUM] = 0;
409 /* On early versions, we must use the 16-bit condition-code register,
410 which has another name. */
411 if (cris_cpu_version < 8)
412 reg_names[CRIS_CC0_REGNUM] = "ccr";
415 /* Return current_function_uses_pic_offset_table. For use in cris.md,
416 since some generated files do not include function.h. */
419 cris_cfun_uses_pic_table (void)
421 return current_function_uses_pic_offset_table;
424 /* Given an rtx, return the text string corresponding to the CODE of X.
425 Intended for use in the assembly language output section of a
426 define_insn. */
428 const char *
429 cris_op_str (rtx x)
431 cris_output_insn_is_bound = 0;
432 switch (GET_CODE (x))
434 case PLUS:
435 return "add";
436 break;
438 case MINUS:
439 return "sub";
440 break;
442 case MULT:
443 /* This function is for retrieving a part of an instruction name for
444 an operator, for immediate output. If that ever happens for
445 MULT, we need to apply TARGET_MUL_BUG in the caller. Make sure
446 we notice. */
447 internal_error ("MULT case in cris_op_str");
448 break;
450 case DIV:
451 return "div";
452 break;
454 case AND:
455 return "and";
456 break;
458 case IOR:
459 return "or";
460 break;
462 case XOR:
463 return "xor";
464 break;
466 case NOT:
467 return "not";
468 break;
470 case ASHIFT:
471 return "lsl";
472 break;
474 case LSHIFTRT:
475 return "lsr";
476 break;
478 case ASHIFTRT:
479 return "asr";
480 break;
482 case UMIN:
483 /* Used to control the sign/zero-extend character for the 'E' modifier.
484 BOUND has none. */
485 cris_output_insn_is_bound = 1;
486 return "bound";
487 break;
489 default:
490 return "Unknown operator";
491 break;
495 /* Emit an error message when we're in an asm, and a fatal error for
496 "normal" insns. Formatted output isn't easily implemented, since we
497 use output_operand_lossage to output the actual message and handle the
498 categorization of the error. */
500 static void
501 cris_operand_lossage (const char *msgid, rtx op)
503 debug_rtx (op);
504 output_operand_lossage ("%s", msgid);
507 /* Print an index part of an address to file. */
509 static void
510 cris_print_index (rtx index, FILE *file)
512 /* Make the index "additive" unless we'll output a negative number, in
513 which case the sign character is free (as in free beer). */
514 if (!CONST_INT_P (index) || INTVAL (index) >= 0)
515 putc ('+', file);
517 if (REG_P (index))
518 fprintf (file, "$%s.b", reg_names[REGNO (index)]);
519 else if (CONSTANT_P (index))
520 cris_output_addr_const (file, index);
521 else if (GET_CODE (index) == MULT)
523 fprintf (file, "$%s.",
524 reg_names[REGNO (XEXP (index, 0))]);
526 putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file);
528 else if (GET_CODE (index) == SIGN_EXTEND && MEM_P (XEXP (index, 0)))
530 rtx inner = XEXP (index, 0);
531 rtx inner_inner = XEXP (inner, 0);
533 if (GET_CODE (inner_inner) == POST_INC)
535 fprintf (file, "[$%s+].",
536 reg_names[REGNO (XEXP (inner_inner, 0))]);
537 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
539 else
541 fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]);
543 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
546 else if (MEM_P (index))
548 rtx inner = XEXP (index, 0);
549 if (GET_CODE (inner) == POST_INC)
550 fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]);
551 else
552 fprintf (file, "[$%s].d", reg_names[REGNO (inner)]);
554 else
555 cris_operand_lossage ("unexpected index-type in cris_print_index",
556 index);
559 /* Print a base rtx of an address to file. */
561 static void
562 cris_print_base (rtx base, FILE *file)
564 if (REG_P (base))
565 fprintf (file, "$%s", reg_names[REGNO (base)]);
566 else if (GET_CODE (base) == POST_INC)
568 gcc_assert (REGNO (XEXP (base, 0)) != CRIS_ACR_REGNUM);
569 fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]);
571 else
572 cris_operand_lossage ("unexpected base-type in cris_print_base",
573 base);
576 /* Usable as a guard in expressions. */
579 cris_fatal (char *arg)
581 internal_error (arg);
583 /* We'll never get here; this is just to appease compilers. */
584 return 0;
587 /* Return nonzero if REGNO is an ordinary register that *needs* to be
588 saved together with other registers, possibly by a MOVEM instruction,
589 or is saved for target-independent reasons. There may be
590 target-dependent reasons to save the register anyway; this is just a
591 wrapper for a complicated conditional. */
593 static int
594 cris_reg_saved_in_regsave_area (unsigned int regno, bool got_really_used)
596 return
597 (((df_regs_ever_live_p (regno)
598 && !call_used_regs[regno])
599 || (regno == PIC_OFFSET_TABLE_REGNUM
600 && (got_really_used
601 /* It is saved anyway, if there would be a gap. */
602 || (flag_pic
603 && df_regs_ever_live_p (regno + 1)
604 && !call_used_regs[regno + 1]))))
605 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
606 && regno != CRIS_SRP_REGNUM)
607 || (current_function_calls_eh_return
608 && (regno == EH_RETURN_DATA_REGNO (0)
609 || regno == EH_RETURN_DATA_REGNO (1)
610 || regno == EH_RETURN_DATA_REGNO (2)
611 || regno == EH_RETURN_DATA_REGNO (3)));
614 /* Return nonzero if there are regs mentioned in the insn that are not all
615 in the call_used regs. This is part of the decision whether an insn
616 can be put in the epilogue. */
618 static int
619 saved_regs_mentioned (rtx x)
621 int i;
622 const char *fmt;
623 RTX_CODE code;
625 /* Mainly stolen from refers_to_regno_p in rtlanal.c. */
627 code = GET_CODE (x);
629 switch (code)
631 case REG:
632 i = REGNO (x);
633 return !call_used_regs[i];
635 case SUBREG:
636 /* If this is a SUBREG of a hard reg, we can see exactly which
637 registers are being modified. Otherwise, handle normally. */
638 i = REGNO (SUBREG_REG (x));
639 return !call_used_regs[i];
641 default:
645 fmt = GET_RTX_FORMAT (code);
646 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
648 if (fmt[i] == 'e')
650 if (saved_regs_mentioned (XEXP (x, i)))
651 return 1;
653 else if (fmt[i] == 'E')
655 int j;
656 for (j = XVECLEN (x, i) - 1; j >=0; j--)
657 if (saved_regs_mentioned (XEXP (x, i)))
658 return 1;
662 return 0;
665 /* The PRINT_OPERAND worker. */
667 void
668 cris_print_operand (FILE *file, rtx x, int code)
670 rtx operand = x;
672 /* Size-strings corresponding to MULT expressions. */
673 static const char *const mults[] = { "BAD:0", ".b", ".w", "BAD:3", ".d" };
675 /* New code entries should just be added to the switch below. If
676 handling is finished, just return. If handling was just a
677 modification of the operand, the modified operand should be put in
678 "operand", and then do a break to let default handling
679 (zero-modifier) output the operand. */
681 switch (code)
683 case 'b':
684 /* Print the unsigned supplied integer as if it were signed
685 and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc. */
686 if (!CONST_INT_P (x)
687 || ! CONST_OK_FOR_LETTER_P (INTVAL (x), 'O'))
688 LOSE_AND_RETURN ("invalid operand for 'b' modifier", x);
689 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
690 INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535));
691 return;
693 case 'x':
694 /* Print assembler code for operator. */
695 fprintf (file, "%s", cris_op_str (operand));
696 return;
698 case 'o':
700 /* A movem modifier working on a parallel; output the register
701 name. */
702 int regno;
704 if (GET_CODE (x) != PARALLEL)
705 LOSE_AND_RETURN ("invalid operand for 'o' modifier", x);
707 /* The second item can be (set reg (plus reg const)) to denote a
708 postincrement. */
709 regno
710 = (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS
711 ? XVECLEN (x, 0) - 2
712 : XVECLEN (x, 0) - 1);
714 fprintf (file, "$%s", reg_names [regno]);
716 return;
718 case 'O':
720 /* A similar movem modifier; output the memory operand. */
721 rtx addr;
723 if (GET_CODE (x) != PARALLEL)
724 LOSE_AND_RETURN ("invalid operand for 'O' modifier", x);
726 /* The lowest mem operand is in the first item, but perhaps it
727 needs to be output as postincremented. */
728 addr = MEM_P (SET_SRC (XVECEXP (x, 0, 0)))
729 ? XEXP (SET_SRC (XVECEXP (x, 0, 0)), 0)
730 : XEXP (SET_DEST (XVECEXP (x, 0, 0)), 0);
732 /* The second item can be a (set reg (plus reg const)) to denote
733 a modification. */
734 if (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS)
736 /* It's a post-increment, if the address is a naked (reg). */
737 if (REG_P (addr))
738 addr = gen_rtx_POST_INC (SImode, addr);
739 else
741 /* Otherwise, it's a side-effect; RN=RN+M. */
742 fprintf (file, "[$%s=$%s%s%d]",
743 reg_names [REGNO (SET_DEST (XVECEXP (x, 0, 1)))],
744 reg_names [REGNO (XEXP (addr, 0))],
745 INTVAL (XEXP (addr, 1)) < 0 ? "" : "+",
746 (int) INTVAL (XEXP (addr, 1)));
747 return;
750 output_address (addr);
752 return;
754 case 'p':
755 /* Adjust a power of two to its log2. */
756 if (!CONST_INT_P (x) || exact_log2 (INTVAL (x)) < 0 )
757 LOSE_AND_RETURN ("invalid operand for 'p' modifier", x);
758 fprintf (file, "%d", exact_log2 (INTVAL (x)));
759 return;
761 case 's':
762 /* For an integer, print 'b' or 'w' if <= 255 or <= 65535
763 respectively. This modifier also terminates the inhibiting
764 effects of the 'x' modifier. */
765 cris_output_insn_is_bound = 0;
766 if (GET_MODE (x) == VOIDmode && CONST_INT_P (x))
768 if (INTVAL (x) >= 0)
770 if (INTVAL (x) <= 255)
771 putc ('b', file);
772 else if (INTVAL (x) <= 65535)
773 putc ('w', file);
774 else
775 putc ('d', file);
777 else
778 putc ('d', file);
779 return;
782 /* For a non-integer, print the size of the operand. */
783 putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode)
784 ? 'd' : GET_MODE (x) == HImode ? 'w'
785 : GET_MODE (x) == QImode ? 'b'
786 /* If none of the above, emit an erroneous size letter. */
787 : 'X',
788 file);
789 return;
791 case 'z':
792 /* Const_int: print b for -127 <= x <= 255,
793 w for -32768 <= x <= 65535, else die. */
794 if (!CONST_INT_P (x)
795 || INTVAL (x) < -32768 || INTVAL (x) > 65535)
796 LOSE_AND_RETURN ("invalid operand for 'z' modifier", x);
797 putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file);
798 return;
800 case 'Z':
801 /* If this is a GOT-symbol, print the size-letter corresponding to
802 -fpic/-fPIC. For everything else, print "d". */
803 putc ((flag_pic == 1
804 && GET_CODE (x) == CONST
805 && GET_CODE (XEXP (x, 0)) == UNSPEC
806 && XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREAD)
807 ? 'w' : 'd', file);
808 return;
810 case '#':
811 /* Output a 'nop' if there's nothing for the delay slot.
812 This method stolen from the sparc files. */
813 if (dbr_sequence_length () == 0)
814 fputs ("\n\tnop", file);
815 return;
817 case '!':
818 /* Output directive for alignment padded with "nop" insns.
819 Optimizing for size, it's plain 4-byte alignment, otherwise we
820 align the section to a cache-line (32 bytes) and skip at max 2
821 bytes, i.e. we skip if it's the last insn on a cache-line. The
822 latter is faster by a small amount (for two test-programs 99.6%
823 and 99.9%) and larger by a small amount (ditto 100.1% and
824 100.2%). This is supposed to be the simplest yet performance-
825 wise least intrusive way to make sure the immediately following
826 (supposed) muls/mulu insn isn't located at the end of a
827 cache-line. */
828 if (TARGET_MUL_BUG)
829 fputs (optimize_size
830 ? ".p2alignw 2,0x050f\n\t"
831 : ".p2alignw 5,0x050f,2\n\t", file);
832 return;
834 case ':':
835 /* The PIC register. */
836 if (! flag_pic)
837 internal_error ("invalid use of ':' modifier");
838 fprintf (file, "$%s", reg_names [PIC_OFFSET_TABLE_REGNUM]);
839 return;
841 case 'H':
842 /* Print high (most significant) part of something. */
843 switch (GET_CODE (operand))
845 case CONST_INT:
846 /* If we're having 64-bit HOST_WIDE_INTs, the whole (DImode)
847 value is kept here, and so may be other than 0 or -1. */
848 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
849 INTVAL (operand_subword (operand, 1, 0, DImode)));
850 return;
852 case CONST_DOUBLE:
853 /* High part of a long long constant. */
854 if (GET_MODE (operand) == VOIDmode)
856 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_HIGH (x));
857 return;
859 else
860 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
862 case REG:
863 /* Print reg + 1. Check that there's not an attempt to print
864 high-parts of registers like stack-pointer or higher, except
865 for SRP (where the "high part" is MOF). */
866 if (REGNO (operand) > STACK_POINTER_REGNUM - 2
867 && (REGNO (operand) != CRIS_SRP_REGNUM
868 || CRIS_SRP_REGNUM + 1 != CRIS_MOF_REGNUM
869 || fixed_regs[CRIS_MOF_REGNUM] != 0))
870 LOSE_AND_RETURN ("bad register", operand);
871 fprintf (file, "$%s", reg_names[REGNO (operand) + 1]);
872 return;
874 case MEM:
875 /* Adjust memory address to high part. */
877 rtx adj_mem = operand;
878 int size
879 = GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT;
881 /* Adjust so we can use two SImode in DImode.
882 Calling adj_offsettable_operand will make sure it is an
883 offsettable address. Don't do this for a postincrement
884 though; it should remain as it was. */
885 if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC)
886 adj_mem
887 = adjust_address (adj_mem, GET_MODE (adj_mem), size / 2);
889 output_address (XEXP (adj_mem, 0));
890 return;
893 default:
894 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
897 case 'L':
898 /* Strip the MEM expression. */
899 operand = XEXP (operand, 0);
900 break;
902 case 'e':
903 /* Like 'E', but ignore state set by 'x'. FIXME: Use code
904 iterators and attributes in cris.md to avoid the need for %x
905 and %E (and %e) and state passed between those modifiers. */
906 cris_output_insn_is_bound = 0;
907 /* FALL THROUGH. */
908 case 'E':
909 /* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless
910 cris_output_insn_is_bound is nonzero. */
911 if (GET_CODE (operand) != SIGN_EXTEND
912 && GET_CODE (operand) != ZERO_EXTEND
913 && !CONST_INT_P (operand))
914 LOSE_AND_RETURN ("invalid operand for 'e' modifier", x);
916 if (cris_output_insn_is_bound)
918 cris_output_insn_is_bound = 0;
919 return;
922 putc (GET_CODE (operand) == SIGN_EXTEND
923 || (CONST_INT_P (operand) && INTVAL (operand) < 0)
924 ? 's' : 'u', file);
925 return;
927 case 'm':
928 /* Print the size letter of the inner element. We can do it by
929 calling ourselves with the 's' modifier. */
930 if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND)
931 LOSE_AND_RETURN ("invalid operand for 'm' modifier", x);
932 cris_print_operand (file, XEXP (operand, 0), 's');
933 return;
935 case 'M':
936 /* Print the least significant part of operand. */
937 if (GET_CODE (operand) == CONST_DOUBLE)
939 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
940 return;
942 else if (HOST_BITS_PER_WIDE_INT > 32 && CONST_INT_P (operand))
944 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
945 INTVAL (x) & ((unsigned int) 0x7fffffff * 2 + 1));
946 return;
948 /* Otherwise the least significant part equals the normal part,
949 so handle it normally. */
950 break;
952 case 'A':
953 /* When emitting an add for the high part of a DImode constant, we
954 want to use addq for 0 and adds.w for -1. */
955 if (!CONST_INT_P (operand))
956 LOSE_AND_RETURN ("invalid operand for 'A' modifier", x);
957 fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq");
958 return;
960 case 'd':
961 /* If this is a GOT symbol, force it to be emitted as :GOT and
962 :GOTPLT regardless of -fpic (i.e. not as :GOT16, :GOTPLT16).
963 Avoid making this too much of a special case. */
964 if (flag_pic == 1 && CONSTANT_P (operand))
966 int flag_pic_save = flag_pic;
968 flag_pic = 2;
969 cris_output_addr_const (file, operand);
970 flag_pic = flag_pic_save;
971 return;
973 break;
975 case 'D':
976 /* When emitting an sub for the high part of a DImode constant, we
977 want to use subq for 0 and subs.w for -1. */
978 if (!CONST_INT_P (operand))
979 LOSE_AND_RETURN ("invalid operand for 'D' modifier", x);
980 fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq");
981 return;
983 case 'S':
984 /* Print the operand as the index-part of an address.
985 Easiest way out is to use cris_print_index. */
986 cris_print_index (operand, file);
987 return;
989 case 'T':
990 /* Print the size letter for an operand to a MULT, which must be a
991 const_int with a suitable value. */
992 if (!CONST_INT_P (operand) || INTVAL (operand) > 4)
993 LOSE_AND_RETURN ("invalid operand for 'T' modifier", x);
994 fprintf (file, "%s", mults[INTVAL (operand)]);
995 return;
997 case 'u':
998 /* Print "u.w" if a GOT symbol and flag_pic == 1, else ".d". */
999 if (flag_pic == 1
1000 && GET_CODE (operand) == CONST
1001 && GET_CODE (XEXP (operand, 0)) == UNSPEC
1002 && XINT (XEXP (operand, 0), 1) == CRIS_UNSPEC_GOTREAD)
1003 fprintf (file, "u.w");
1004 else
1005 fprintf (file, ".d");
1006 return;
1008 case 0:
1009 /* No code, print as usual. */
1010 break;
1012 default:
1013 LOSE_AND_RETURN ("invalid operand modifier letter", x);
1016 /* Print an operand as without a modifier letter. */
1017 switch (GET_CODE (operand))
1019 case REG:
1020 if (REGNO (operand) > 15
1021 && REGNO (operand) != CRIS_MOF_REGNUM
1022 && REGNO (operand) != CRIS_SRP_REGNUM
1023 && REGNO (operand) != CRIS_CC0_REGNUM)
1024 internal_error ("internal error: bad register: %d", REGNO (operand));
1025 fprintf (file, "$%s", reg_names[REGNO (operand)]);
1026 return;
1028 case MEM:
1029 output_address (XEXP (operand, 0));
1030 return;
1032 case CONST_DOUBLE:
1033 if (GET_MODE (operand) == VOIDmode)
1034 /* A long long constant. */
1035 output_addr_const (file, operand);
1036 else
1038 /* Only single precision is allowed as plain operands the
1039 moment. FIXME: REAL_VALUE_FROM_CONST_DOUBLE isn't
1040 documented. */
1041 REAL_VALUE_TYPE r;
1042 long l;
1044 /* FIXME: Perhaps check overflow of the "single". */
1045 REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
1046 REAL_VALUE_TO_TARGET_SINGLE (r, l);
1048 fprintf (file, "0x%lx", l);
1050 return;
1052 case UNSPEC:
1053 /* Fall through. */
1054 case CONST:
1055 cris_output_addr_const (file, operand);
1056 return;
1058 case MULT:
1059 case ASHIFT:
1061 /* For a (MULT (reg X) const_int) we output "rX.S". */
1062 int i = CONST_INT_P (XEXP (operand, 1))
1063 ? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0));
1064 rtx reg = CONST_INT_P (XEXP (operand, 1))
1065 ? XEXP (operand, 0) : XEXP (operand, 1);
1067 if (!REG_P (reg)
1068 || (!CONST_INT_P (XEXP (operand, 0))
1069 && !CONST_INT_P (XEXP (operand, 1))))
1070 LOSE_AND_RETURN ("unexpected multiplicative operand", x);
1072 cris_print_base (reg, file);
1073 fprintf (file, ".%c",
1074 i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b'
1075 : i == 4 ? 'd'
1076 : (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w'
1077 : 'd');
1078 return;
1081 default:
1082 /* No need to handle all strange variants, let output_addr_const
1083 do it for us. */
1084 if (CONSTANT_P (operand))
1086 cris_output_addr_const (file, operand);
1087 return;
1090 LOSE_AND_RETURN ("unexpected operand", x);
1094 /* The PRINT_OPERAND_ADDRESS worker. */
1096 void
1097 cris_print_operand_address (FILE *file, rtx x)
1099 /* All these were inside MEM:s so output indirection characters. */
1100 putc ('[', file);
1102 if (CONSTANT_ADDRESS_P (x))
1103 cris_output_addr_const (file, x);
1104 else if (BASE_OR_AUTOINCR_P (x))
1105 cris_print_base (x, file);
1106 else if (GET_CODE (x) == PLUS)
1108 rtx x1, x2;
1110 x1 = XEXP (x, 0);
1111 x2 = XEXP (x, 1);
1112 if (BASE_P (x1))
1114 cris_print_base (x1, file);
1115 cris_print_index (x2, file);
1117 else if (BASE_P (x2))
1119 cris_print_base (x2, file);
1120 cris_print_index (x1, file);
1122 else
1123 LOSE_AND_RETURN ("unrecognized address", x);
1125 else if (MEM_P (x))
1127 /* A DIP. Output more indirection characters. */
1128 putc ('[', file);
1129 cris_print_base (XEXP (x, 0), file);
1130 putc (']', file);
1132 else
1133 LOSE_AND_RETURN ("unrecognized address", x);
1135 putc (']', file);
1138 /* The RETURN_ADDR_RTX worker.
1139 We mark that the return address is used, either by EH or
1140 __builtin_return_address, for use by the function prologue and
1141 epilogue. FIXME: This isn't optimal; we just use the mark in the
1142 prologue and epilogue to say that the return address is to be stored
1143 in the stack frame. We could return SRP for leaf-functions and use the
1144 initial-value machinery. */
1147 cris_return_addr_rtx (int count, rtx frameaddr ATTRIBUTE_UNUSED)
1149 cfun->machine->needs_return_address_on_stack = 1;
1151 /* The return-address is stored just above the saved frame-pointer (if
1152 present). Apparently we can't eliminate from the frame-pointer in
1153 that direction, so use the incoming args (maybe pretended) pointer. */
1154 return count == 0
1155 ? gen_rtx_MEM (Pmode, plus_constant (virtual_incoming_args_rtx, -4))
1156 : NULL_RTX;
1159 /* Accessor used in cris.md:return because cfun->machine isn't available
1160 there. */
1162 bool
1163 cris_return_address_on_stack (void)
1165 return df_regs_ever_live_p (CRIS_SRP_REGNUM)
1166 || cfun->machine->needs_return_address_on_stack;
1169 /* Accessor used in cris.md:return because cfun->machine isn't available
1170 there. */
1172 bool
1173 cris_return_address_on_stack_for_return (void)
1175 return cfun->machine->return_type == CRIS_RETINSN_RET ? false
1176 : cris_return_address_on_stack ();
1179 /* This used to be the INITIAL_FRAME_POINTER_OFFSET worker; now only
1180 handles FP -> SP elimination offset. */
1182 static int
1183 cris_initial_frame_pointer_offset (void)
1185 int regno;
1187 /* Initial offset is 0 if we don't have a frame pointer. */
1188 int offs = 0;
1189 bool got_really_used = false;
1191 if (current_function_uses_pic_offset_table)
1193 push_topmost_sequence ();
1194 got_really_used
1195 = reg_used_between_p (pic_offset_table_rtx, get_insns (),
1196 NULL_RTX);
1197 pop_topmost_sequence ();
1200 /* And 4 for each register pushed. */
1201 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1202 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1203 offs += 4;
1205 /* And then, last, we add the locals allocated. */
1206 offs += get_frame_size ();
1208 /* And more; the accumulated args size. */
1209 offs += current_function_outgoing_args_size;
1211 /* Then round it off, in case we use aligned stack. */
1212 if (TARGET_STACK_ALIGN)
1213 offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1;
1215 return offs;
1218 /* The INITIAL_ELIMINATION_OFFSET worker.
1219 Calculate the difference between imaginary registers such as frame
1220 pointer and the stack pointer. Used to eliminate the frame pointer
1221 and imaginary arg pointer. */
1224 cris_initial_elimination_offset (int fromreg, int toreg)
1226 int fp_sp_offset
1227 = cris_initial_frame_pointer_offset ();
1229 /* We should be able to use regs_ever_live and related prologue
1230 information here, or alpha should not as well. */
1231 bool return_address_on_stack = cris_return_address_on_stack ();
1233 /* Here we act as if the frame-pointer were needed. */
1234 int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0);
1236 if (fromreg == ARG_POINTER_REGNUM
1237 && toreg == FRAME_POINTER_REGNUM)
1238 return ap_fp_offset;
1240 /* Between the frame pointer and the stack are only "normal" stack
1241 variables and saved registers. */
1242 if (fromreg == FRAME_POINTER_REGNUM
1243 && toreg == STACK_POINTER_REGNUM)
1244 return fp_sp_offset;
1246 /* We need to balance out the frame pointer here. */
1247 if (fromreg == ARG_POINTER_REGNUM
1248 && toreg == STACK_POINTER_REGNUM)
1249 return ap_fp_offset + fp_sp_offset - 4;
1251 gcc_unreachable ();
1254 /* Worker function for LEGITIMIZE_RELOAD_ADDRESS. */
1256 bool
1257 cris_reload_address_legitimized (rtx x,
1258 enum machine_mode mode ATTRIBUTE_UNUSED,
1259 int opnum ATTRIBUTE_UNUSED,
1260 int itype,
1261 int ind_levels ATTRIBUTE_UNUSED)
1263 enum reload_type type = itype;
1264 rtx op0, op1;
1265 rtx *op0p;
1266 rtx *op1p;
1268 if (GET_CODE (x) != PLUS)
1269 return false;
1271 if (TARGET_V32)
1272 return false;
1274 op0 = XEXP (x, 0);
1275 op0p = &XEXP (x, 0);
1276 op1 = XEXP (x, 1);
1277 op1p = &XEXP (x, 1);
1279 if (!REG_P (op1))
1280 return false;
1282 if (GET_CODE (op0) == SIGN_EXTEND && MEM_P (XEXP (op0, 0)))
1284 rtx op00 = XEXP (op0, 0);
1285 rtx op000 = XEXP (op00, 0);
1286 rtx *op000p = &XEXP (op00, 0);
1288 if ((GET_MODE (op00) == HImode || GET_MODE (op00) == QImode)
1289 && (REG_P (op000)
1290 || (GET_CODE (op000) == POST_INC && REG_P (XEXP (op000, 0)))))
1292 bool something_reloaded = false;
1294 if (GET_CODE (op000) == POST_INC
1295 && REG_P (XEXP (op000, 0))
1296 && REGNO (XEXP (op000, 0)) > CRIS_LAST_GENERAL_REGISTER)
1297 /* No, this gets too complicated and is too rare to care
1298 about trying to improve on the general code Here.
1299 As the return-value is an all-or-nothing indicator, we
1300 punt on the other register too. */
1301 return false;
1303 if ((REG_P (op000)
1304 && REGNO (op000) > CRIS_LAST_GENERAL_REGISTER))
1306 /* The address of the inner mem is a pseudo or wrong
1307 reg: reload that. */
1308 push_reload (op000, NULL_RTX, op000p, NULL, GENERAL_REGS,
1309 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
1310 something_reloaded = true;
1313 if (REGNO (op1) > CRIS_LAST_GENERAL_REGISTER)
1315 /* Base register is a pseudo or wrong reg: reload it. */
1316 push_reload (op1, NULL_RTX, op1p, NULL, GENERAL_REGS,
1317 GET_MODE (x), VOIDmode, 0, 0,
1318 opnum, type);
1319 something_reloaded = true;
1322 gcc_assert (something_reloaded);
1324 return true;
1328 return false;
1331 /* Worker function for REGISTER_MOVE_COST. */
1334 cris_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1335 enum reg_class from, enum reg_class to)
1337 if (!TARGET_V32)
1339 /* Pretend that classes that we don't support are ALL_REGS, so
1340 we give them the highest cost. */
1341 if (from != SPECIAL_REGS && from != MOF_REGS
1342 && from != GENERAL_REGS && from != GENNONACR_REGS)
1343 from = ALL_REGS;
1345 if (to != SPECIAL_REGS && to != MOF_REGS
1346 && to != GENERAL_REGS && to != GENNONACR_REGS)
1347 to = ALL_REGS;
1350 /* Can't move to and from a SPECIAL_REGS register, so we have to say
1351 their move cost within that class is higher. How about 7? That's 3
1352 for a move to a GENERAL_REGS register, 3 for the move from the
1353 GENERAL_REGS register, and 1 for the increased register pressure.
1354 Also, it's higher than the memory move cost, which is in order.
1355 We also do this for ALL_REGS, since we don't want that class to be
1356 preferred (even to memory) at all where GENERAL_REGS doesn't fit.
1357 Whenever it's about to be used, it's for SPECIAL_REGS. If we don't
1358 present a higher cost for ALL_REGS than memory, a SPECIAL_REGS may be
1359 used when a GENERAL_REGS should be used, even if there are call-saved
1360 GENERAL_REGS left to allocate. This is because the fall-back when
1361 the most preferred register class isn't available, isn't the next
1362 (or next good) wider register class, but the *most widest* register
1363 class. */
1365 if ((reg_classes_intersect_p (from, SPECIAL_REGS)
1366 && reg_classes_intersect_p (to, SPECIAL_REGS))
1367 || from == ALL_REGS || to == ALL_REGS)
1368 return 7;
1370 if (reg_classes_intersect_p (from, SPECIAL_REGS)
1371 || reg_classes_intersect_p (to, SPECIAL_REGS))
1372 return 3;
1374 return 2;
1377 /* Worker for cris_notice_update_cc; handles the "normal" cases.
1378 FIXME: this code is historical; its functionality should be
1379 refactored to look at insn attributes and moved to
1380 cris_notice_update_cc. Except, we better lose cc0 entirely. */
1382 static void
1383 cris_normal_notice_update_cc (rtx exp, rtx insn)
1385 /* "Normal" means, for:
1386 (set (cc0) (...)):
1387 CC is (...).
1389 (set (reg) (...)):
1390 CC is (reg) and (...) - unless (...) is 0 or reg is a special
1391 register or (v32 and (...) is -32..-1), then CC does not change.
1392 CC_NO_OVERFLOW unless (...) is reg or mem.
1394 (set (mem) (...)):
1395 CC does not change.
1397 (set (pc) (...)):
1398 CC does not change.
1400 (parallel
1401 (set (reg1) (mem (bdap/biap)))
1402 (set (reg2) (bdap/biap))):
1403 CC is (reg1) and (mem (reg2))
1405 (parallel
1406 (set (mem (bdap/biap)) (reg1)) [or 0]
1407 (set (reg2) (bdap/biap))):
1408 CC does not change.
1410 (where reg and mem includes strict_low_parts variants thereof)
1412 For all others, assume CC is clobbered.
1413 Note that we do not have to care about setting CC_NO_OVERFLOW,
1414 since the overflow flag is set to 0 (i.e. right) for
1415 instructions where it does not have any sane sense, but where
1416 other flags have meanings. (This includes shifts; the carry is
1417 not set by them).
1419 Note that there are other parallel constructs we could match,
1420 but we don't do that yet. */
1422 if (GET_CODE (exp) == SET)
1424 /* FIXME: Check when this happens. It looks like we should
1425 actually do a CC_STATUS_INIT here to be safe. */
1426 if (SET_DEST (exp) == pc_rtx)
1427 return;
1429 /* Record CC0 changes, so we do not have to output multiple
1430 test insns. */
1431 if (SET_DEST (exp) == cc0_rtx)
1433 CC_STATUS_INIT;
1434 cc_status.value1 = SET_SRC (exp);
1436 /* Handle flags for the special btstq on one bit. */
1437 if (GET_CODE (SET_SRC (exp)) == ZERO_EXTRACT
1438 && XEXP (SET_SRC (exp), 1) == const1_rtx)
1440 if (CONST_INT_P (XEXP (SET_SRC (exp), 0)))
1441 /* Using cmpq. */
1442 cc_status.flags = CC_INVERTED;
1443 else
1444 /* A one-bit btstq. */
1445 cc_status.flags = CC_Z_IN_NOT_N;
1448 if (GET_CODE (SET_SRC (exp)) == COMPARE)
1450 if (!REG_P (XEXP (SET_SRC (exp), 0))
1451 && XEXP (SET_SRC (exp), 1) != const0_rtx)
1452 /* For some reason gcc will not canonicalize compare
1453 operations, reversing the sign by itself if
1454 operands are in wrong order. */
1455 /* (But NOT inverted; eq is still eq.) */
1456 cc_status.flags = CC_REVERSED;
1458 /* This seems to be overlooked by gcc. FIXME: Check again.
1459 FIXME: Is it really safe? */
1460 cc_status.value2
1461 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1462 XEXP (SET_SRC (exp), 0),
1463 XEXP (SET_SRC (exp), 1));
1465 return;
1467 else if (REG_P (SET_DEST (exp))
1468 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1469 && REG_P (XEXP (SET_DEST (exp), 0))))
1471 /* A register is set; normally CC is set to show that no
1472 test insn is needed. Catch the exceptions. */
1474 /* If not to cc0, then no "set"s in non-natural mode give
1475 ok cc0... */
1476 if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1477 || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1479 /* ... except add:s and sub:s in DImode. */
1480 if (GET_MODE (SET_DEST (exp)) == DImode
1481 && (GET_CODE (SET_SRC (exp)) == PLUS
1482 || GET_CODE (SET_SRC (exp)) == MINUS))
1484 CC_STATUS_INIT;
1485 cc_status.value1 = SET_DEST (exp);
1486 cc_status.value2 = SET_SRC (exp);
1488 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1489 cc_status.value2))
1490 cc_status.value2 = 0;
1492 /* Add and sub may set V, which gets us
1493 unoptimizable results in "gt" and "le" condition
1494 codes. */
1495 cc_status.flags |= CC_NO_OVERFLOW;
1497 return;
1500 else if (SET_SRC (exp) == const0_rtx
1501 || (REG_P (SET_SRC (exp))
1502 && (REGNO (SET_SRC (exp))
1503 > CRIS_LAST_GENERAL_REGISTER))
1504 || (TARGET_V32
1505 && GET_CODE (SET_SRC (exp)) == CONST_INT
1506 && CONST_OK_FOR_LETTER_P (INTVAL (SET_SRC (exp)),
1507 'I')))
1509 /* There's no CC0 change for this case. Just check
1510 for overlap. */
1511 if (cc_status.value1
1512 && modified_in_p (cc_status.value1, insn))
1513 cc_status.value1 = 0;
1515 if (cc_status.value2
1516 && modified_in_p (cc_status.value2, insn))
1517 cc_status.value2 = 0;
1519 return;
1521 else
1523 CC_STATUS_INIT;
1524 cc_status.value1 = SET_DEST (exp);
1525 cc_status.value2 = SET_SRC (exp);
1527 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1528 cc_status.value2))
1529 cc_status.value2 = 0;
1531 /* Some operations may set V, which gets us
1532 unoptimizable results in "gt" and "le" condition
1533 codes. */
1534 if (GET_CODE (SET_SRC (exp)) == PLUS
1535 || GET_CODE (SET_SRC (exp)) == MINUS
1536 || GET_CODE (SET_SRC (exp)) == NEG)
1537 cc_status.flags |= CC_NO_OVERFLOW;
1539 /* For V32, nothing with a register destination sets
1540 C and V usefully. */
1541 if (TARGET_V32)
1542 cc_status.flags |= CC_NO_OVERFLOW;
1544 return;
1547 else if (MEM_P (SET_DEST (exp))
1548 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1549 && MEM_P (XEXP (SET_DEST (exp), 0))))
1551 /* When SET to MEM, then CC is not changed (except for
1552 overlap). */
1553 if (cc_status.value1
1554 && modified_in_p (cc_status.value1, insn))
1555 cc_status.value1 = 0;
1557 if (cc_status.value2
1558 && modified_in_p (cc_status.value2, insn))
1559 cc_status.value2 = 0;
1561 return;
1564 else if (GET_CODE (exp) == PARALLEL)
1566 if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1567 && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1568 && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1570 if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1571 && MEM_P (XEXP (XVECEXP (exp, 0, 0), 1)))
1573 CC_STATUS_INIT;
1575 /* For "move.S [rx=ry+o],rz", say CC reflects
1576 value1=rz and value2=[rx] */
1577 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1578 cc_status.value2
1579 = replace_equiv_address (XEXP (XVECEXP (exp, 0, 0), 1),
1580 XEXP (XVECEXP (exp, 0, 1), 0));
1582 /* Huh? A side-effect cannot change the destination
1583 register. */
1584 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1585 cc_status.value2))
1586 internal_error ("internal error: sideeffect-insn affecting main effect");
1588 /* For V32, moves to registers don't set C and V. */
1589 if (TARGET_V32)
1590 cc_status.flags |= CC_NO_OVERFLOW;
1591 return;
1593 else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1594 || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1595 && MEM_P (XEXP (XVECEXP (exp, 0, 0), 0)))
1597 /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1598 say flags are not changed, except for overlap. */
1599 if (cc_status.value1
1600 && modified_in_p (cc_status.value1, insn))
1601 cc_status.value1 = 0;
1603 if (cc_status.value2
1604 && modified_in_p (cc_status.value2, insn))
1605 cc_status.value2 = 0;
1607 return;
1612 /* If we got here, the case wasn't covered by the code above. */
1613 CC_STATUS_INIT;
1616 /* This function looks into the pattern to see how this insn affects
1617 condition codes.
1619 Used when to eliminate test insns before a condition-code user,
1620 such as a "scc" insn or a conditional branch. This includes
1621 checking if the entities that cc was updated by, are changed by the
1622 operation.
1624 Currently a jumble of the old peek-inside-the-insn and the newer
1625 check-cc-attribute methods. */
1627 void
1628 cris_notice_update_cc (rtx exp, rtx insn)
1630 enum attr_cc attrval = get_attr_cc (insn);
1632 /* Check if user specified "-mcc-init" as a bug-workaround. Remember
1633 to still set CC_REVERSED as below, since that's required by some
1634 compare insn alternatives. (FIXME: GCC should do this virtual
1635 operand swap by itself.) A test-case that may otherwise fail is
1636 gcc.c-torture/execute/20000217-1.c -O0 and -O1. */
1637 if (TARGET_CCINIT)
1639 CC_STATUS_INIT;
1641 if (attrval == CC_REV)
1642 cc_status.flags = CC_REVERSED;
1643 return;
1646 /* Slowly, we're converting to using attributes to control the setting
1647 of condition-code status. */
1648 switch (attrval)
1650 case CC_NONE:
1651 /* Even if it is "none", a setting may clobber a previous
1652 cc-value, so check. */
1653 if (GET_CODE (exp) == SET)
1655 if (cc_status.value1
1656 && modified_in_p (cc_status.value1, insn))
1657 cc_status.value1 = 0;
1659 if (cc_status.value2
1660 && modified_in_p (cc_status.value2, insn))
1661 cc_status.value2 = 0;
1663 return;
1665 case CC_CLOBBER:
1666 CC_STATUS_INIT;
1667 return;
1669 case CC_REV:
1670 case CC_NOOV32:
1671 case CC_NORMAL:
1672 cris_normal_notice_update_cc (exp, insn);
1674 /* The "test" insn doesn't clear (carry and) overflow on V32. We
1675 can change bge => bpl and blt => bmi by passing on to the cc0
1676 user that V should not be considered; bgt and ble are taken
1677 care of by other methods (see {tst,cmp}{si,hi,qi}). */
1678 if (attrval == CC_NOOV32 && TARGET_V32)
1679 cc_status.flags |= CC_NO_OVERFLOW;
1680 return;
1682 default:
1683 internal_error ("unknown cc_attr value");
1686 CC_STATUS_INIT;
1689 /* Return != 0 if the return sequence for the current function is short,
1690 like "ret" or "jump [sp+]". Prior to reloading, we can't tell if
1691 registers must be saved, so return 0 then. */
1693 bool
1694 cris_simple_epilogue (void)
1696 unsigned int regno;
1697 unsigned int reglimit = STACK_POINTER_REGNUM;
1698 bool got_really_used = false;
1700 if (! reload_completed
1701 || frame_pointer_needed
1702 || get_frame_size () != 0
1703 || current_function_pretend_args_size
1704 || current_function_args_size
1705 || current_function_outgoing_args_size
1706 || current_function_calls_eh_return
1708 /* If we're not supposed to emit prologue and epilogue, we must
1709 not emit return-type instructions. */
1710 || !TARGET_PROLOGUE_EPILOGUE)
1711 return false;
1713 /* Can't return from stacked return address with v32. */
1714 if (TARGET_V32 && cris_return_address_on_stack ())
1715 return false;
1717 if (current_function_uses_pic_offset_table)
1719 push_topmost_sequence ();
1720 got_really_used
1721 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
1722 pop_topmost_sequence ();
1725 /* No simple epilogue if there are saved registers. */
1726 for (regno = 0; regno < reglimit; regno++)
1727 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1728 return false;
1730 return true;
1733 /* Expand a return insn (just one insn) marked as using SRP or stack
1734 slot depending on parameter ON_STACK. */
1736 void
1737 cris_expand_return (bool on_stack)
1739 /* FIXME: emit a parallel with a USE for SRP or the stack-slot, to
1740 tell "ret" from "jump [sp+]". Some, but not all, other parts of
1741 GCC expect just (return) to do the right thing when optimizing, so
1742 we do that until they're fixed. Currently, all return insns in a
1743 function must be the same (not really a limiting factor) so we need
1744 to check that it doesn't change half-way through. */
1745 emit_jump_insn (gen_rtx_RETURN (VOIDmode));
1747 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_RET || !on_stack);
1748 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_JUMP || on_stack);
1750 cfun->machine->return_type
1751 = on_stack ? CRIS_RETINSN_JUMP : CRIS_RETINSN_RET;
1754 /* Compute a (partial) cost for rtx X. Return true if the complete
1755 cost has been computed, and false if subexpressions should be
1756 scanned. In either case, *TOTAL contains the cost result. */
1758 static bool
1759 cris_rtx_costs (rtx x, int code, int outer_code, int *total)
1761 switch (code)
1763 case CONST_INT:
1765 HOST_WIDE_INT val = INTVAL (x);
1766 if (val == 0)
1767 *total = 0;
1768 else if (val < 32 && val >= -32)
1769 *total = 1;
1770 /* Eight or 16 bits are a word and cycle more expensive. */
1771 else if (val <= 32767 && val >= -32768)
1772 *total = 2;
1773 /* A 32-bit constant (or very seldom, unsigned 16 bits) costs
1774 another word. FIXME: This isn't linear to 16 bits. */
1775 else
1776 *total = 4;
1777 return true;
1780 case LABEL_REF:
1781 *total = 6;
1782 return true;
1784 case CONST:
1785 case SYMBOL_REF:
1786 *total = 6;
1787 return true;
1789 case CONST_DOUBLE:
1790 if (x != CONST0_RTX (GET_MODE (x) == VOIDmode ? DImode : GET_MODE (x)))
1791 *total = 12;
1792 else
1793 /* Make 0.0 cheap, else test-insns will not be used. */
1794 *total = 0;
1795 return true;
1797 case MULT:
1798 /* Identify values that are no powers of two. Powers of 2 are
1799 taken care of already and those values should not be changed. */
1800 if (!CONST_INT_P (XEXP (x, 1))
1801 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1803 /* If we have a multiply insn, then the cost is between
1804 1 and 2 "fast" instructions. */
1805 if (TARGET_HAS_MUL_INSNS)
1807 *total = COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2;
1808 return true;
1811 /* Estimate as 4 + 4 * #ofbits. */
1812 *total = COSTS_N_INSNS (132);
1813 return true;
1815 return false;
1817 case UDIV:
1818 case MOD:
1819 case UMOD:
1820 case DIV:
1821 if (!CONST_INT_P (XEXP (x, 1))
1822 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1824 /* Estimate this as 4 + 8 * #of bits. */
1825 *total = COSTS_N_INSNS (260);
1826 return true;
1828 return false;
1830 case AND:
1831 if (CONST_INT_P (XEXP (x, 1))
1832 /* Two constants may actually happen before optimization. */
1833 && !CONST_INT_P (XEXP (x, 0))
1834 && !CONST_OK_FOR_LETTER_P (INTVAL (XEXP (x, 1)), 'I'))
1836 *total = (rtx_cost (XEXP (x, 0), outer_code) + 2
1837 + 2 * GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))));
1838 return true;
1840 return false;
1842 case ZERO_EXTEND: case SIGN_EXTEND:
1843 *total = rtx_cost (XEXP (x, 0), outer_code);
1844 return true;
1846 default:
1847 return false;
1851 /* The ADDRESS_COST worker. */
1853 static int
1854 cris_address_cost (rtx x)
1856 /* The metric to use for the cost-macros is unclear.
1857 The metric used here is (the number of cycles needed) / 2,
1858 where we consider equal a cycle for a word of code and a cycle to
1859 read memory. FIXME: Adding "+ 1" to all values would avoid
1860 returning 0, as tree-ssa-loop-ivopts.c as of r128272 "normalizes"
1861 0 to 1, thereby giving equal costs to [rN + rM] and [rN].
1862 Unfortunately(?) such a hack would expose other pessimizations,
1863 at least with g++.dg/tree-ssa/ivopts-1.C, adding insns to the
1864 loop there, without apparent reason. */
1866 /* The cheapest addressing modes get 0, since nothing extra is needed. */
1867 if (BASE_OR_AUTOINCR_P (x))
1868 return 0;
1870 /* An indirect mem must be a DIP. This means two bytes extra for code,
1871 and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */
1872 if (MEM_P (x))
1873 return (2 + 4) / 2;
1875 /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
1876 an extra DIP prefix and 4 bytes of constant in most cases. */
1877 if (CONSTANT_P (x))
1878 return (2 + 4) / 2;
1880 /* Handle BIAP and BDAP prefixes. */
1881 if (GET_CODE (x) == PLUS)
1883 rtx tem1 = XEXP (x, 0);
1884 rtx tem2 = XEXP (x, 1);
1886 /* We'll "assume" canonical RTX. */
1887 gcc_assert (REG_P (tem1) || GET_CODE (tem1) == MULT);
1889 /* A BIAP is 2 extra bytes for the prefix insn, nothing more. We
1890 recognize the typical MULT which is always in tem1 because of
1891 insn canonicalization. */
1892 if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
1893 || REG_P (tem2))
1894 return 2 / 2;
1896 /* A BDAP (quick) is 2 extra bytes. Any constant operand to the
1897 PLUS is always found in tem2. */
1898 if (CONST_INT_P (tem2) && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
1899 return 2 / 2;
1901 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
1902 bytes. */
1903 if (CONST_INT_P (tem2) && CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
1904 return (2 + 2) / 2;
1906 /* A BDAP with some other constant is 2 bytes extra. */
1907 if (CONSTANT_P (tem2))
1908 return (2 + 2 + 2) / 2;
1910 /* BDAP with something indirect should have a higher cost than
1911 BIAP with register. FIXME: Should it cost like a MEM or more? */
1912 return (2 + 2 + 2) / 2;
1915 /* What else? Return a high cost. It matters only for valid
1916 addressing modes. */
1917 return 10;
1920 /* Check various objections to the side-effect. Used in the test-part
1921 of an anonymous insn describing an insn with a possible side-effect.
1922 Returns nonzero if the implied side-effect is ok.
1924 code : PLUS or MULT
1925 ops : An array of rtx:es. lreg, rreg, rval,
1926 The variables multop and other_op are indexes into this,
1927 or -1 if they are not applicable.
1928 lreg : The register that gets assigned in the side-effect.
1929 rreg : One register in the side-effect expression
1930 rval : The other register, or an int.
1931 multop : An integer to multiply rval with.
1932 other_op : One of the entities of the main effect,
1933 whose mode we must consider. */
1936 cris_side_effect_mode_ok (enum rtx_code code, rtx *ops,
1937 int lreg, int rreg, int rval,
1938 int multop, int other_op)
1940 /* Find what value to multiply with, for rx =ry + rz * n. */
1941 int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
1943 rtx reg_rtx = ops[rreg];
1944 rtx val_rtx = ops[rval];
1946 /* The operands may be swapped. Canonicalize them in reg_rtx and
1947 val_rtx, where reg_rtx always is a reg (for this constraint to
1948 match). */
1949 if (! BASE_P (reg_rtx))
1950 reg_rtx = val_rtx, val_rtx = ops[rreg];
1952 /* Don't forget to check that reg_rtx really is a reg. If it isn't,
1953 we have no business. */
1954 if (! BASE_P (reg_rtx))
1955 return 0;
1957 /* Don't do this when -mno-split. */
1958 if (!TARGET_SIDE_EFFECT_PREFIXES)
1959 return 0;
1961 /* The mult expression may be hidden in lreg. FIXME: Add more
1962 commentary about that. */
1963 if (GET_CODE (val_rtx) == MULT)
1965 mult = INTVAL (XEXP (val_rtx, 1));
1966 val_rtx = XEXP (val_rtx, 0);
1967 code = MULT;
1970 /* First check the "other operand". */
1971 if (other_op >= 0)
1973 if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
1974 return 0;
1976 /* Check if the lvalue register is the same as the "other
1977 operand". If so, the result is undefined and we shouldn't do
1978 this. FIXME: Check again. */
1979 if ((BASE_P (ops[lreg])
1980 && BASE_P (ops[other_op])
1981 && REGNO (ops[lreg]) == REGNO (ops[other_op]))
1982 || rtx_equal_p (ops[other_op], ops[lreg]))
1983 return 0;
1986 /* Do not accept frame_pointer_rtx as any operand. */
1987 if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
1988 || ops[rval] == frame_pointer_rtx
1989 || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
1990 return 0;
1992 if (code == PLUS
1993 && ! BASE_P (val_rtx))
1996 /* Do not allow rx = rx + n if a normal add or sub with same size
1997 would do. */
1998 if (rtx_equal_p (ops[lreg], reg_rtx)
1999 && CONST_INT_P (val_rtx)
2000 && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2001 return 0;
2003 /* Check allowed cases, like [r(+)?].[bwd] and const. */
2004 if (CONSTANT_P (val_rtx))
2005 return 1;
2007 if (MEM_P (val_rtx) && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
2008 return 1;
2010 if (GET_CODE (val_rtx) == SIGN_EXTEND
2011 && MEM_P (XEXP (val_rtx, 0))
2012 && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
2013 return 1;
2015 /* If we got here, it's not a valid addressing mode. */
2016 return 0;
2018 else if (code == MULT
2019 || (code == PLUS && BASE_P (val_rtx)))
2021 /* Do not allow rx = rx + ry.S, since it doesn't give better code. */
2022 if (rtx_equal_p (ops[lreg], reg_rtx)
2023 || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2024 return 0;
2026 /* Do not allow bad multiply-values. */
2027 if (mult != 1 && mult != 2 && mult != 4)
2028 return 0;
2030 /* Only allow r + ... */
2031 if (! BASE_P (reg_rtx))
2032 return 0;
2034 /* If we got here, all seems ok.
2035 (All checks need to be done above). */
2036 return 1;
2039 /* If we get here, the caller got its initial tests wrong. */
2040 internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
2043 /* Whether next_cc0_user of insn is LE or GT or requires a real compare
2044 insn for other reasons. */
2046 bool
2047 cris_cc0_user_requires_cmp (rtx insn)
2049 rtx cc0_user = NULL;
2050 rtx body;
2051 rtx set;
2053 gcc_assert (insn != NULL);
2055 if (!TARGET_V32)
2056 return false;
2058 cc0_user = next_cc0_user (insn);
2059 if (cc0_user == NULL)
2060 return false;
2062 body = PATTERN (cc0_user);
2063 set = single_set (cc0_user);
2065 /* Users can be sCC and bCC. */
2066 if (JUMP_P (cc0_user)
2067 && GET_CODE (body) == SET
2068 && SET_DEST (body) == pc_rtx
2069 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2070 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx)
2072 return
2073 GET_CODE (XEXP (SET_SRC (body), 0)) == GT
2074 || GET_CODE (XEXP (SET_SRC (body), 0)) == LE;
2076 else if (set)
2078 return
2079 GET_CODE (SET_SRC (body)) == GT
2080 || GET_CODE (SET_SRC (body)) == LE;
2083 gcc_unreachable ();
2086 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2087 does not handle the case where the IN operand is strict_low_part; it
2088 does handle it for X. Test-case in Axis-20010516. This function takes
2089 care of that for THIS port. FIXME: strict_low_part is going away
2090 anyway. */
2092 static int
2093 cris_reg_overlap_mentioned_p (rtx x, rtx in)
2095 /* The function reg_overlap_mentioned now handles when X is
2096 strict_low_part, but not when IN is a STRICT_LOW_PART. */
2097 if (GET_CODE (in) == STRICT_LOW_PART)
2098 in = XEXP (in, 0);
2100 return reg_overlap_mentioned_p (x, in);
2103 /* The TARGET_ASM_NAMED_SECTION worker.
2104 We just dispatch to the functions for ELF and a.out. */
2106 void
2107 cris_target_asm_named_section (const char *name, unsigned int flags,
2108 tree decl)
2110 if (! TARGET_ELF)
2111 default_no_named_section (name, flags, decl);
2112 else
2113 default_elf_asm_named_section (name, flags, decl);
2116 /* Return TRUE iff X is a CONST valid for e.g. indexing.
2117 ANY_OPERAND is 0 if X is in a CALL_P insn or movsi, 1
2118 elsewhere. */
2120 bool
2121 cris_valid_pic_const (rtx x, bool any_operand)
2123 gcc_assert (flag_pic);
2125 switch (GET_CODE (x))
2127 case CONST_INT:
2128 case CONST_DOUBLE:
2129 return true;
2130 default:
2134 if (GET_CODE (x) != CONST)
2135 return false;
2137 x = XEXP (x, 0);
2139 /* Handle (const (plus (unspec .. UNSPEC_GOTREL) (const_int ...))). */
2140 if (GET_CODE (x) == PLUS
2141 && GET_CODE (XEXP (x, 0)) == UNSPEC
2142 && (XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREL
2143 || XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_PCREL)
2144 && CONST_INT_P (XEXP (x, 1)))
2145 x = XEXP (x, 0);
2147 if (GET_CODE (x) == UNSPEC)
2148 switch (XINT (x, 1))
2150 /* A PCREL operand is only valid for call and movsi. */
2151 case CRIS_UNSPEC_PLT_PCREL:
2152 case CRIS_UNSPEC_PCREL:
2153 return !any_operand;
2155 case CRIS_UNSPEC_PLT_GOTREL:
2156 case CRIS_UNSPEC_PLTGOTREAD:
2157 case CRIS_UNSPEC_GOTREAD:
2158 case CRIS_UNSPEC_GOTREL:
2159 return true;
2160 default:
2161 gcc_unreachable ();
2164 return cris_pic_symbol_type_of (x) == cris_no_symbol;
2167 /* Helper function to find the right PIC-type symbol to generate,
2168 given the original (non-PIC) representation. */
2170 enum cris_pic_symbol_type
2171 cris_pic_symbol_type_of (rtx x)
2173 switch (GET_CODE (x))
2175 case SYMBOL_REF:
2176 return SYMBOL_REF_LOCAL_P (x)
2177 ? cris_rel_symbol : cris_got_symbol;
2179 case LABEL_REF:
2180 return cris_rel_symbol;
2182 case CONST:
2183 return cris_pic_symbol_type_of (XEXP (x, 0));
2185 case PLUS:
2186 case MINUS:
2188 enum cris_pic_symbol_type t1 = cris_pic_symbol_type_of (XEXP (x, 0));
2189 enum cris_pic_symbol_type t2 = cris_pic_symbol_type_of (XEXP (x, 1));
2191 gcc_assert (t1 == cris_no_symbol || t2 == cris_no_symbol);
2193 if (t1 == cris_got_symbol || t1 == cris_got_symbol)
2194 return cris_got_symbol_needing_fixup;
2196 return t1 != cris_no_symbol ? t1 : t2;
2199 case CONST_INT:
2200 case CONST_DOUBLE:
2201 return cris_no_symbol;
2203 case UNSPEC:
2204 /* Likely an offsettability-test attempting to add a constant to
2205 a GOTREAD symbol, which can't be handled. */
2206 return cris_invalid_pic_symbol;
2208 default:
2209 fatal_insn ("unrecognized supposed constant", x);
2212 gcc_unreachable ();
2215 /* The LEGITIMATE_PIC_OPERAND_P worker. */
2218 cris_legitimate_pic_operand (rtx x)
2220 /* Symbols are not valid PIC operands as-is; just constants. */
2221 return cris_valid_pic_const (x, true);
2224 /* The ASM_OUTPUT_CASE_END worker. */
2226 void
2227 cris_asm_output_case_end (FILE *stream, int num, rtx table)
2229 if (TARGET_V32)
2231 rtx whole_jump_insn = PATTERN (PREV_INSN (PREV_INSN (table)));
2233 /* This can be a SEQUENCE, meaning the delay-slot of the jump is
2234 filled. */
2235 rtx parallel_jump
2236 = (GET_CODE (whole_jump_insn) == SEQUENCE
2237 ? PATTERN (XVECEXP (whole_jump_insn, 0, 0)) : whole_jump_insn);
2239 asm_fprintf (stream,
2240 "\t.word %LL%d-.%s\n",
2241 CODE_LABEL_NUMBER (XEXP (XEXP (XEXP (XVECEXP
2242 (parallel_jump, 0, 0),
2243 1), 2), 0)),
2244 (TARGET_PDEBUG ? "; default" : ""));
2245 return;
2248 asm_fprintf (stream,
2249 "\t.word %LL%d-%LL%d%s\n",
2250 CODE_LABEL_NUMBER (XEXP
2251 (XEXP
2252 (XEXP
2253 (XVECEXP
2254 (PATTERN
2255 (PREV_INSN
2256 (PREV_INSN (table))), 0, 0), 1),
2257 2), 0)),
2258 num,
2259 (TARGET_PDEBUG ? "; default" : ""));
2262 /* TARGET_HANDLE_OPTION worker. We just store the values into local
2263 variables here. Checks for correct semantics are in
2264 cris_override_options. */
2266 static bool
2267 cris_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED,
2268 int value ATTRIBUTE_UNUSED)
2270 switch (code)
2272 case OPT_metrax100:
2273 target_flags
2274 |= (MASK_SVINTO
2275 + MASK_ETRAX4_ADD
2276 + MASK_ALIGN_BY_32);
2277 break;
2279 case OPT_mno_etrax100:
2280 target_flags
2281 &= ~(MASK_SVINTO
2282 + MASK_ETRAX4_ADD
2283 + MASK_ALIGN_BY_32);
2284 break;
2286 case OPT_m32_bit:
2287 case OPT_m32bit:
2288 target_flags
2289 |= (MASK_STACK_ALIGN
2290 + MASK_CONST_ALIGN
2291 + MASK_DATA_ALIGN
2292 + MASK_ALIGN_BY_32);
2293 break;
2295 case OPT_m16_bit:
2296 case OPT_m16bit:
2297 target_flags
2298 |= (MASK_STACK_ALIGN
2299 + MASK_CONST_ALIGN
2300 + MASK_DATA_ALIGN);
2301 break;
2303 case OPT_m8_bit:
2304 case OPT_m8bit:
2305 target_flags
2306 &= ~(MASK_STACK_ALIGN
2307 + MASK_CONST_ALIGN
2308 + MASK_DATA_ALIGN);
2309 break;
2311 default:
2312 break;
2315 CRIS_SUBTARGET_HANDLE_OPTION(code, arg, value);
2317 return true;
2320 /* The OVERRIDE_OPTIONS worker.
2321 As is the norm, this also parses -mfoo=bar type parameters. */
2323 void
2324 cris_override_options (void)
2326 if (cris_max_stackframe_str)
2328 cris_max_stackframe = atoi (cris_max_stackframe_str);
2330 /* Do some sanity checking. */
2331 if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2332 internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2333 cris_max_stackframe, 0x20000000);
2336 /* Let "-metrax4" and "-metrax100" change the cpu version. */
2337 if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2338 cris_cpu_version = CRIS_CPU_SVINTO;
2339 else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2340 cris_cpu_version = CRIS_CPU_ETRAX4;
2342 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2343 if (cris_cpu_str)
2345 cris_cpu_version
2346 = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2348 if (strcmp ("etrax4", cris_cpu_str) == 0)
2349 cris_cpu_version = 3;
2351 if (strcmp ("svinto", cris_cpu_str) == 0
2352 || strcmp ("etrax100", cris_cpu_str) == 0)
2353 cris_cpu_version = 8;
2355 if (strcmp ("ng", cris_cpu_str) == 0
2356 || strcmp ("etrax100lx", cris_cpu_str) == 0)
2357 cris_cpu_version = 10;
2359 if (cris_cpu_version < 0 || cris_cpu_version > 32)
2360 error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2361 cris_cpu_str);
2363 /* Set the target flags. */
2364 if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2365 target_flags |= MASK_ETRAX4_ADD;
2367 /* If this is Svinto or higher, align for 32 bit accesses. */
2368 if (cris_cpu_version >= CRIS_CPU_SVINTO)
2369 target_flags
2370 |= (MASK_SVINTO | MASK_ALIGN_BY_32
2371 | MASK_STACK_ALIGN | MASK_CONST_ALIGN
2372 | MASK_DATA_ALIGN);
2374 /* Note that we do not add new flags when it can be completely
2375 described with a macro that uses -mcpu=X. So
2376 TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */
2379 if (cris_tune_str)
2381 int cris_tune
2382 = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2384 if (strcmp ("etrax4", cris_tune_str) == 0)
2385 cris_tune = 3;
2387 if (strcmp ("svinto", cris_tune_str) == 0
2388 || strcmp ("etrax100", cris_tune_str) == 0)
2389 cris_tune = 8;
2391 if (strcmp ("ng", cris_tune_str) == 0
2392 || strcmp ("etrax100lx", cris_tune_str) == 0)
2393 cris_tune = 10;
2395 if (cris_tune < 0 || cris_tune > 32)
2396 error ("unknown CRIS cpu version specification in -mtune= : %s",
2397 cris_tune_str);
2399 if (cris_tune >= CRIS_CPU_SVINTO)
2400 /* We have currently nothing more to tune than alignment for
2401 memory accesses. */
2402 target_flags
2403 |= (MASK_STACK_ALIGN | MASK_CONST_ALIGN
2404 | MASK_DATA_ALIGN | MASK_ALIGN_BY_32);
2407 if (cris_cpu_version >= CRIS_CPU_V32)
2408 target_flags &= ~(MASK_SIDE_EFFECT_PREFIXES|MASK_MUL_BUG);
2410 if (flag_pic)
2412 /* Use error rather than warning, so invalid use is easily
2413 detectable. Still change to the values we expect, to avoid
2414 further errors. */
2415 if (! TARGET_LINUX)
2417 error ("-fPIC and -fpic are not supported in this configuration");
2418 flag_pic = 0;
2421 /* Turn off function CSE. We need to have the addresses reach the
2422 call expanders to get PLT-marked, as they could otherwise be
2423 compared against zero directly or indirectly. After visiting the
2424 call expanders they will then be cse:ed, as the call expanders
2425 force_reg the addresses, effectively forcing flag_no_function_cse
2426 to 0. */
2427 flag_no_function_cse = 1;
2430 if (write_symbols == DWARF2_DEBUG && ! TARGET_ELF)
2432 warning (0, "that particular -g option is invalid with -maout and -melinux");
2433 write_symbols = DBX_DEBUG;
2436 /* Set the per-function-data initializer. */
2437 init_machine_status = cris_init_machine_status;
2440 /* The TARGET_ASM_OUTPUT_MI_THUNK worker. */
2442 static void
2443 cris_asm_output_mi_thunk (FILE *stream,
2444 tree thunkdecl ATTRIBUTE_UNUSED,
2445 HOST_WIDE_INT delta,
2446 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
2447 tree funcdecl)
2449 if (delta > 0)
2450 fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2451 ADDITIVE_SIZE_MODIFIER (delta), delta,
2452 reg_names[CRIS_FIRST_ARG_REG]);
2453 else if (delta < 0)
2454 fprintf (stream, "\tsub%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2455 ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2456 reg_names[CRIS_FIRST_ARG_REG]);
2458 if (flag_pic)
2460 const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2462 name = (* targetm.strip_name_encoding) (name);
2464 if (TARGET_V32)
2466 fprintf (stream, "\tba ");
2467 assemble_name (stream, name);
2468 fprintf (stream, "%s\n", CRIS_PLT_PCOFFSET_SUFFIX);
2470 else
2472 fprintf (stream, "add.d ");
2473 assemble_name (stream, name);
2474 fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2477 else
2479 fprintf (stream, "jump ");
2480 assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2481 fprintf (stream, "\n");
2483 if (TARGET_V32)
2484 fprintf (stream, "\tnop\n");
2488 /* Boilerplate emitted at start of file.
2490 NO_APP *only at file start* means faster assembly. It also means
2491 comments are not allowed. In some cases comments will be output
2492 for debugging purposes. Make sure they are allowed then.
2494 We want a .file directive only if TARGET_ELF. */
2495 static void
2496 cris_file_start (void)
2498 /* These expressions can vary at run time, so we cannot put
2499 them into TARGET_INITIALIZER. */
2500 targetm.file_start_app_off = !(TARGET_PDEBUG || flag_print_asm_name);
2501 targetm.file_start_file_directive = TARGET_ELF;
2503 default_file_start ();
2506 /* Rename the function calls for integer multiply and divide. */
2507 static void
2508 cris_init_libfuncs (void)
2510 set_optab_libfunc (smul_optab, SImode, "__Mul");
2511 set_optab_libfunc (sdiv_optab, SImode, "__Div");
2512 set_optab_libfunc (udiv_optab, SImode, "__Udiv");
2513 set_optab_libfunc (smod_optab, SImode, "__Mod");
2514 set_optab_libfunc (umod_optab, SImode, "__Umod");
2517 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2518 mark functions. */
2520 void
2521 cris_init_expanders (void)
2523 /* Nothing here at the moment. */
2526 /* Zero initialization is OK for all current fields. */
2528 static struct machine_function *
2529 cris_init_machine_status (void)
2531 return ggc_alloc_cleared (sizeof (struct machine_function));
2534 /* Split a 2 word move (DI or presumably DF) into component parts.
2535 Originally a copy of gen_split_move_double in m32r.c. */
2538 cris_split_movdx (rtx *operands)
2540 enum machine_mode mode = GET_MODE (operands[0]);
2541 rtx dest = operands[0];
2542 rtx src = operands[1];
2543 rtx val;
2545 /* We used to have to handle (SUBREG (MEM)) here, but that should no
2546 longer happen; after reload there are no SUBREGs any more, and we're
2547 only called after reload. */
2548 CRIS_ASSERT (GET_CODE (dest) != SUBREG && GET_CODE (src) != SUBREG);
2550 start_sequence ();
2551 if (REG_P (dest))
2553 int dregno = REGNO (dest);
2555 /* Reg-to-reg copy. */
2556 if (REG_P (src))
2558 int sregno = REGNO (src);
2560 int reverse = (dregno == sregno + 1);
2562 /* We normally copy the low-numbered register first. However, if
2563 the first register operand 0 is the same as the second register of
2564 operand 1, we must copy in the opposite order. */
2565 emit_insn (gen_rtx_SET (VOIDmode,
2566 operand_subword (dest, reverse, TRUE, mode),
2567 operand_subword (src, reverse, TRUE, mode)));
2569 emit_insn (gen_rtx_SET (VOIDmode,
2570 operand_subword (dest, !reverse, TRUE, mode),
2571 operand_subword (src, !reverse, TRUE, mode)));
2573 /* Constant-to-reg copy. */
2574 else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE)
2576 rtx words[2];
2577 split_double (src, &words[0], &words[1]);
2578 emit_insn (gen_rtx_SET (VOIDmode,
2579 operand_subword (dest, 0, TRUE, mode),
2580 words[0]));
2582 emit_insn (gen_rtx_SET (VOIDmode,
2583 operand_subword (dest, 1, TRUE, mode),
2584 words[1]));
2586 /* Mem-to-reg copy. */
2587 else if (MEM_P (src))
2589 /* If the high-address word is used in the address, we must load it
2590 last. Otherwise, load it first. */
2591 rtx addr = XEXP (src, 0);
2592 int reverse
2593 = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2595 /* The original code implies that we can't do
2596 move.x [rN+],rM move.x [rN],rM+1
2597 when rN is dead, because of REG_NOTES damage. That is
2598 consistent with what I've seen, so don't try it.
2600 We have two different cases here; if the addr is POST_INC,
2601 just pass it through, otherwise add constants. */
2603 if (GET_CODE (addr) == POST_INC)
2605 rtx mem;
2606 rtx insn;
2608 /* Whenever we emit insns with post-incremented
2609 addresses ourselves, we must add a post-inc note
2610 manually. */
2611 mem = change_address (src, SImode, addr);
2612 insn
2613 = gen_rtx_SET (VOIDmode,
2614 operand_subword (dest, 0, TRUE, mode), mem);
2615 insn = emit_insn (insn);
2616 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2617 REG_NOTES (insn)
2618 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2619 REG_NOTES (insn));
2621 mem = copy_rtx (mem);
2622 insn
2623 = gen_rtx_SET (VOIDmode,
2624 operand_subword (dest, 1, TRUE, mode), mem);
2625 insn = emit_insn (insn);
2626 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2627 REG_NOTES (insn)
2628 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2629 REG_NOTES (insn));
2631 else
2633 /* Make sure we don't get any other addresses with
2634 embedded postincrements. They should be stopped in
2635 GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2636 safety. */
2637 if (side_effects_p (addr))
2638 fatal_insn ("unexpected side-effects in address", addr);
2640 emit_insn (gen_rtx_SET
2641 (VOIDmode,
2642 operand_subword (dest, reverse, TRUE, mode),
2643 change_address
2644 (src, SImode,
2645 plus_constant (addr,
2646 reverse * UNITS_PER_WORD))));
2647 emit_insn (gen_rtx_SET
2648 (VOIDmode,
2649 operand_subword (dest, ! reverse, TRUE, mode),
2650 change_address
2651 (src, SImode,
2652 plus_constant (addr,
2653 (! reverse) *
2654 UNITS_PER_WORD))));
2657 else
2658 internal_error ("Unknown src");
2660 /* Reg-to-mem copy or clear mem. */
2661 else if (MEM_P (dest)
2662 && (REG_P (src)
2663 || src == const0_rtx
2664 || src == CONST0_RTX (DFmode)))
2666 rtx addr = XEXP (dest, 0);
2668 if (GET_CODE (addr) == POST_INC)
2670 rtx mem;
2671 rtx insn;
2673 /* Whenever we emit insns with post-incremented addresses
2674 ourselves, we must add a post-inc note manually. */
2675 mem = change_address (dest, SImode, addr);
2676 insn
2677 = gen_rtx_SET (VOIDmode,
2678 mem, operand_subword (src, 0, TRUE, mode));
2679 insn = emit_insn (insn);
2680 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2681 REG_NOTES (insn)
2682 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2683 REG_NOTES (insn));
2685 mem = copy_rtx (mem);
2686 insn
2687 = gen_rtx_SET (VOIDmode,
2688 mem,
2689 operand_subword (src, 1, TRUE, mode));
2690 insn = emit_insn (insn);
2691 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2692 REG_NOTES (insn)
2693 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2694 REG_NOTES (insn));
2696 else
2698 /* Make sure we don't get any other addresses with embedded
2699 postincrements. They should be stopped in
2700 GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */
2701 if (side_effects_p (addr))
2702 fatal_insn ("unexpected side-effects in address", addr);
2704 emit_insn (gen_rtx_SET
2705 (VOIDmode,
2706 change_address (dest, SImode, addr),
2707 operand_subword (src, 0, TRUE, mode)));
2709 emit_insn (gen_rtx_SET
2710 (VOIDmode,
2711 change_address (dest, SImode,
2712 plus_constant (addr,
2713 UNITS_PER_WORD)),
2714 operand_subword (src, 1, TRUE, mode)));
2718 else
2719 internal_error ("Unknown dest");
2721 val = get_insns ();
2722 end_sequence ();
2723 return val;
2726 /* The expander for the prologue pattern name. */
2728 void
2729 cris_expand_prologue (void)
2731 int regno;
2732 int size = get_frame_size ();
2733 /* Shorten the used name for readability. */
2734 int cfoa_size = current_function_outgoing_args_size;
2735 int last_movem_reg = -1;
2736 int framesize = 0;
2737 rtx mem, insn;
2738 int return_address_on_stack = cris_return_address_on_stack ();
2739 int got_really_used = false;
2740 int n_movem_regs = 0;
2741 int pretend = current_function_pretend_args_size;
2743 /* Don't do anything if no prologues or epilogues are wanted. */
2744 if (!TARGET_PROLOGUE_EPILOGUE)
2745 return;
2747 CRIS_ASSERT (size >= 0);
2749 if (current_function_uses_pic_offset_table)
2751 /* A reference may have been optimized out (like the abort () in
2752 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
2753 it's still used. */
2754 push_topmost_sequence ();
2755 got_really_used
2756 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
2757 pop_topmost_sequence ();
2760 /* Align the size to what's best for the CPU model. */
2761 if (TARGET_STACK_ALIGN)
2762 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
2764 if (pretend)
2766 /* See also cris_setup_incoming_varargs where
2767 cfun->machine->stdarg_regs is set. There are other setters of
2768 current_function_pretend_args_size than stdarg handling, like
2769 for an argument passed with parts in R13 and stack. We must
2770 not store R13 into the pretend-area for that case, as GCC does
2771 that itself. "Our" store would be marked as redundant and GCC
2772 will attempt to remove it, which will then be flagged as an
2773 internal error; trying to remove a frame-related insn. */
2774 int stdarg_regs = cfun->machine->stdarg_regs;
2776 framesize += pretend;
2778 for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
2779 stdarg_regs > 0;
2780 regno--, pretend -= 4, stdarg_regs--)
2782 insn = emit_insn (gen_rtx_SET (VOIDmode,
2783 stack_pointer_rtx,
2784 plus_constant (stack_pointer_rtx,
2785 -4)));
2786 /* FIXME: When dwarf2 frame output and unless asynchronous
2787 exceptions, make dwarf2 bundle together all stack
2788 adjustments like it does for registers between stack
2789 adjustments. */
2790 RTX_FRAME_RELATED_P (insn) = 1;
2792 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2793 set_mem_alias_set (mem, get_varargs_alias_set ());
2794 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2796 /* Note the absence of RTX_FRAME_RELATED_P on the above insn:
2797 the value isn't restored, so we don't want to tell dwarf2
2798 that it's been stored to stack, else EH handling info would
2799 get confused. */
2802 /* For other setters of current_function_pretend_args_size, we
2803 just adjust the stack by leaving the remaining size in
2804 "pretend", handled below. */
2807 /* Save SRP if not a leaf function. */
2808 if (return_address_on_stack)
2810 insn = emit_insn (gen_rtx_SET (VOIDmode,
2811 stack_pointer_rtx,
2812 plus_constant (stack_pointer_rtx,
2813 -4 - pretend)));
2814 pretend = 0;
2815 RTX_FRAME_RELATED_P (insn) = 1;
2817 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2818 set_mem_alias_set (mem, get_frame_alias_set ());
2819 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM));
2820 RTX_FRAME_RELATED_P (insn) = 1;
2821 framesize += 4;
2824 /* Set up the frame pointer, if needed. */
2825 if (frame_pointer_needed)
2827 insn = emit_insn (gen_rtx_SET (VOIDmode,
2828 stack_pointer_rtx,
2829 plus_constant (stack_pointer_rtx,
2830 -4 - pretend)));
2831 pretend = 0;
2832 RTX_FRAME_RELATED_P (insn) = 1;
2834 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2835 set_mem_alias_set (mem, get_frame_alias_set ());
2836 insn = emit_move_insn (mem, frame_pointer_rtx);
2837 RTX_FRAME_RELATED_P (insn) = 1;
2839 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
2840 RTX_FRAME_RELATED_P (insn) = 1;
2842 framesize += 4;
2845 /* Between frame-pointer and saved registers lie the area for local
2846 variables. If we get here with "pretended" size remaining, count
2847 it into the general stack size. */
2848 size += pretend;
2850 /* Get a contiguous sequence of registers, starting with R0, that need
2851 to be saved. */
2852 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
2854 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
2856 n_movem_regs++;
2858 /* Check if movem may be used for registers so far. */
2859 if (regno == last_movem_reg + 1)
2860 /* Yes, update next expected register. */
2861 last_movem_reg = regno;
2862 else
2864 /* We cannot use movem for all registers. We have to flush
2865 any movem:ed registers we got so far. */
2866 if (last_movem_reg != -1)
2868 int n_saved
2869 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2871 /* It is a win to use a side-effect assignment for
2872 64 <= size <= 128. But side-effect on movem was
2873 not usable for CRIS v0..3. Also only do it if
2874 side-effects insns are allowed. */
2875 if ((last_movem_reg + 1) * 4 + size >= 64
2876 && (last_movem_reg + 1) * 4 + size <= 128
2877 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2878 && TARGET_SIDE_EFFECT_PREFIXES)
2881 = gen_rtx_MEM (SImode,
2882 plus_constant (stack_pointer_rtx,
2883 -(n_saved * 4 + size)));
2884 set_mem_alias_set (mem, get_frame_alias_set ());
2885 insn
2886 = cris_emit_movem_store (mem, GEN_INT (n_saved),
2887 -(n_saved * 4 + size),
2888 true);
2890 else
2892 insn
2893 = gen_rtx_SET (VOIDmode,
2894 stack_pointer_rtx,
2895 plus_constant (stack_pointer_rtx,
2896 -(n_saved * 4 + size)));
2897 insn = emit_insn (insn);
2898 RTX_FRAME_RELATED_P (insn) = 1;
2900 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2901 set_mem_alias_set (mem, get_frame_alias_set ());
2902 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2903 0, true);
2906 framesize += n_saved * 4 + size;
2907 last_movem_reg = -1;
2908 size = 0;
2911 insn = emit_insn (gen_rtx_SET (VOIDmode,
2912 stack_pointer_rtx,
2913 plus_constant (stack_pointer_rtx,
2914 -4 - size)));
2915 RTX_FRAME_RELATED_P (insn) = 1;
2917 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2918 set_mem_alias_set (mem, get_frame_alias_set ());
2919 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2920 RTX_FRAME_RELATED_P (insn) = 1;
2922 framesize += 4 + size;
2923 size = 0;
2928 /* Check after, if we could movem all registers. This is the normal case. */
2929 if (last_movem_reg != -1)
2931 int n_saved
2932 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2934 /* Side-effect on movem was not usable for CRIS v0..3. Also only
2935 do it if side-effects insns are allowed. */
2936 if ((last_movem_reg + 1) * 4 + size >= 64
2937 && (last_movem_reg + 1) * 4 + size <= 128
2938 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2939 && TARGET_SIDE_EFFECT_PREFIXES)
2942 = gen_rtx_MEM (SImode,
2943 plus_constant (stack_pointer_rtx,
2944 -(n_saved * 4 + size)));
2945 set_mem_alias_set (mem, get_frame_alias_set ());
2946 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2947 -(n_saved * 4 + size), true);
2949 else
2951 insn
2952 = gen_rtx_SET (VOIDmode,
2953 stack_pointer_rtx,
2954 plus_constant (stack_pointer_rtx,
2955 -(n_saved * 4 + size)));
2956 insn = emit_insn (insn);
2957 RTX_FRAME_RELATED_P (insn) = 1;
2959 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2960 set_mem_alias_set (mem, get_frame_alias_set ());
2961 insn = cris_emit_movem_store (mem, GEN_INT (n_saved), 0, true);
2964 framesize += n_saved * 4 + size;
2965 /* We have to put outgoing argument space after regs. */
2966 if (cfoa_size)
2968 insn = emit_insn (gen_rtx_SET (VOIDmode,
2969 stack_pointer_rtx,
2970 plus_constant (stack_pointer_rtx,
2971 -cfoa_size)));
2972 RTX_FRAME_RELATED_P (insn) = 1;
2973 framesize += cfoa_size;
2976 else if ((size + cfoa_size) > 0)
2978 insn = emit_insn (gen_rtx_SET (VOIDmode,
2979 stack_pointer_rtx,
2980 plus_constant (stack_pointer_rtx,
2981 -(cfoa_size + size))));
2982 RTX_FRAME_RELATED_P (insn) = 1;
2983 framesize += size + cfoa_size;
2986 /* Set up the PIC register, if it is used. */
2987 if (got_really_used)
2989 rtx got
2990 = gen_rtx_UNSPEC (SImode, gen_rtvec (1, const0_rtx), CRIS_UNSPEC_GOT);
2991 emit_move_insn (pic_offset_table_rtx, got);
2993 /* FIXME: This is a cover-up for flow2 messing up; it doesn't
2994 follow exceptional paths and tries to delete the GOT load as
2995 unused, if it isn't used on the non-exceptional paths. Other
2996 ports have similar or other cover-ups, or plain bugs marking
2997 the GOT register load as maybe-dead. To see this, remove the
2998 line below and try libsupc++/vec.cc or a trivial
2999 "static void y (); void x () {try {y ();} catch (...) {}}". */
3000 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
3003 if (cris_max_stackframe && framesize > cris_max_stackframe)
3004 warning (0, "stackframe too big: %d bytes", framesize);
3007 /* The expander for the epilogue pattern. */
3009 void
3010 cris_expand_epilogue (void)
3012 int regno;
3013 int size = get_frame_size ();
3014 int last_movem_reg = -1;
3015 int argspace_offset = current_function_outgoing_args_size;
3016 int pretend = current_function_pretend_args_size;
3017 rtx mem;
3018 bool return_address_on_stack = cris_return_address_on_stack ();
3019 /* A reference may have been optimized out
3020 (like the abort () in fde_split in unwind-dw2-fde.c, at least 3.2.1)
3021 so check that it's still used. */
3022 int got_really_used = false;
3023 int n_movem_regs = 0;
3025 if (!TARGET_PROLOGUE_EPILOGUE)
3026 return;
3028 if (current_function_uses_pic_offset_table)
3030 /* A reference may have been optimized out (like the abort () in
3031 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
3032 it's still used. */
3033 push_topmost_sequence ();
3034 got_really_used
3035 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
3036 pop_topmost_sequence ();
3039 /* Align byte count of stack frame. */
3040 if (TARGET_STACK_ALIGN)
3041 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
3043 /* Check how many saved regs we can movem. They start at r0 and must
3044 be contiguous. */
3045 for (regno = 0;
3046 regno < FIRST_PSEUDO_REGISTER;
3047 regno++)
3048 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3050 n_movem_regs++;
3052 if (regno == last_movem_reg + 1)
3053 last_movem_reg = regno;
3054 else
3055 break;
3058 /* If there was only one register that really needed to be saved
3059 through movem, don't use movem. */
3060 if (n_movem_regs == 1)
3061 last_movem_reg = -1;
3063 /* Now emit "normal" move insns for all regs higher than the movem
3064 regs. */
3065 for (regno = FIRST_PSEUDO_REGISTER - 1;
3066 regno > last_movem_reg;
3067 regno--)
3068 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3070 rtx insn;
3072 if (argspace_offset)
3074 /* There is an area for outgoing parameters located before
3075 the saved registers. We have to adjust for that. */
3076 emit_insn (gen_rtx_SET (VOIDmode,
3077 stack_pointer_rtx,
3078 plus_constant (stack_pointer_rtx,
3079 argspace_offset)));
3080 /* Make sure we only do this once. */
3081 argspace_offset = 0;
3084 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3085 stack_pointer_rtx));
3086 set_mem_alias_set (mem, get_frame_alias_set ());
3087 insn = emit_move_insn (gen_rtx_raw_REG (SImode, regno), mem);
3089 /* Whenever we emit insns with post-incremented addresses
3090 ourselves, we must add a post-inc note manually. */
3091 REG_NOTES (insn)
3092 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3095 /* If we have any movem-restore, do it now. */
3096 if (last_movem_reg != -1)
3098 rtx insn;
3100 if (argspace_offset)
3102 emit_insn (gen_rtx_SET (VOIDmode,
3103 stack_pointer_rtx,
3104 plus_constant (stack_pointer_rtx,
3105 argspace_offset)));
3106 argspace_offset = 0;
3109 mem = gen_rtx_MEM (SImode,
3110 gen_rtx_POST_INC (SImode, stack_pointer_rtx));
3111 set_mem_alias_set (mem, get_frame_alias_set ());
3112 insn
3113 = emit_insn (cris_gen_movem_load (mem,
3114 GEN_INT (last_movem_reg + 1), 0));
3115 /* Whenever we emit insns with post-incremented addresses
3116 ourselves, we must add a post-inc note manually. */
3117 if (side_effects_p (PATTERN (insn)))
3118 REG_NOTES (insn)
3119 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3122 /* If we don't clobber all of the allocated stack area (we've already
3123 deallocated saved registers), GCC might want to schedule loads from
3124 the stack to *after* the stack-pointer restore, which introduces an
3125 interrupt race condition. This happened for the initial-value
3126 SRP-restore for g++.dg/eh/registers1.C (noticed by inspection of
3127 other failure for that test). It also happened for the stack slot
3128 for the return value in (one version of)
3129 linux/fs/dcache.c:__d_lookup, at least with "-O2
3130 -fno-omit-frame-pointer". */
3132 /* Restore frame pointer if necessary. */
3133 if (frame_pointer_needed)
3135 rtx insn;
3137 emit_insn (gen_cris_frame_deallocated_barrier ());
3139 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
3140 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3141 stack_pointer_rtx));
3142 set_mem_alias_set (mem, get_frame_alias_set ());
3143 insn = emit_move_insn (frame_pointer_rtx, mem);
3145 /* Whenever we emit insns with post-incremented addresses
3146 ourselves, we must add a post-inc note manually. */
3147 REG_NOTES (insn)
3148 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3150 else if ((size + argspace_offset) != 0)
3152 emit_insn (gen_cris_frame_deallocated_barrier ());
3154 /* If there was no frame-pointer to restore sp from, we must
3155 explicitly deallocate local variables. */
3157 /* Handle space for outgoing parameters that hasn't been handled
3158 yet. */
3159 size += argspace_offset;
3161 emit_insn (gen_rtx_SET (VOIDmode,
3162 stack_pointer_rtx,
3163 plus_constant (stack_pointer_rtx, size)));
3166 /* If this function has no pushed register parameters
3167 (stdargs/varargs), and if it is not a leaf function, then we have
3168 the return address on the stack. */
3169 if (return_address_on_stack && pretend == 0)
3171 if (TARGET_V32 || current_function_calls_eh_return)
3173 rtx mem;
3174 rtx insn;
3175 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3176 mem = gen_rtx_MEM (SImode,
3177 gen_rtx_POST_INC (SImode,
3178 stack_pointer_rtx));
3179 set_mem_alias_set (mem, get_frame_alias_set ());
3180 insn = emit_move_insn (srpreg, mem);
3182 /* Whenever we emit insns with post-incremented addresses
3183 ourselves, we must add a post-inc note manually. */
3184 REG_NOTES (insn)
3185 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3187 if (current_function_calls_eh_return)
3188 emit_insn (gen_addsi3 (stack_pointer_rtx,
3189 stack_pointer_rtx,
3190 gen_rtx_raw_REG (SImode,
3191 CRIS_STACKADJ_REG)));
3192 cris_expand_return (false);
3194 else
3195 cris_expand_return (true);
3197 return;
3200 /* If we pushed some register parameters, then adjust the stack for
3201 them. */
3202 if (pretend != 0)
3204 /* If SRP is stored on the way, we need to restore it first. */
3205 if (return_address_on_stack)
3207 rtx mem;
3208 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3209 rtx insn;
3211 mem = gen_rtx_MEM (SImode,
3212 gen_rtx_POST_INC (SImode,
3213 stack_pointer_rtx));
3214 set_mem_alias_set (mem, get_frame_alias_set ());
3215 insn = emit_move_insn (srpreg, mem);
3217 /* Whenever we emit insns with post-incremented addresses
3218 ourselves, we must add a post-inc note manually. */
3219 REG_NOTES (insn)
3220 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3223 emit_insn (gen_rtx_SET (VOIDmode,
3224 stack_pointer_rtx,
3225 plus_constant (stack_pointer_rtx, pretend)));
3228 /* Perform the "physical" unwinding that the EH machinery calculated. */
3229 if (current_function_calls_eh_return)
3230 emit_insn (gen_addsi3 (stack_pointer_rtx,
3231 stack_pointer_rtx,
3232 gen_rtx_raw_REG (SImode,
3233 CRIS_STACKADJ_REG)));
3234 cris_expand_return (false);
3237 /* Worker function for generating movem from mem for load_multiple. */
3240 cris_gen_movem_load (rtx src, rtx nregs_rtx, int nprefix)
3242 int nregs = INTVAL (nregs_rtx);
3243 rtvec vec;
3244 int eltno = 1;
3245 int i;
3246 rtx srcreg = XEXP (src, 0);
3247 unsigned int regno = nregs - 1;
3248 int regno_inc = -1;
3250 if (TARGET_V32)
3252 regno = 0;
3253 regno_inc = 1;
3256 if (GET_CODE (srcreg) == POST_INC)
3257 srcreg = XEXP (srcreg, 0);
3259 CRIS_ASSERT (REG_P (srcreg));
3261 /* Don't use movem for just one insn. The insns are equivalent except
3262 for the pipeline hazard (on v32); movem does not forward the loaded
3263 registers so there's a three cycles penalty for their use. */
3264 if (nregs == 1)
3265 return gen_movsi (gen_rtx_REG (SImode, 0), src);
3267 vec = rtvec_alloc (nprefix + nregs
3268 + (GET_CODE (XEXP (src, 0)) == POST_INC));
3270 if (GET_CODE (XEXP (src, 0)) == POST_INC)
3272 RTVEC_ELT (vec, nprefix + 1)
3273 = gen_rtx_SET (VOIDmode, srcreg, plus_constant (srcreg, nregs * 4));
3274 eltno++;
3277 src = replace_equiv_address (src, srcreg);
3278 RTVEC_ELT (vec, nprefix)
3279 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno), src);
3280 regno += regno_inc;
3282 for (i = 1; i < nregs; i++, eltno++)
3284 RTVEC_ELT (vec, nprefix + eltno)
3285 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno),
3286 adjust_address_nv (src, SImode, i * 4));
3287 regno += regno_inc;
3290 return gen_rtx_PARALLEL (VOIDmode, vec);
3293 /* Worker function for generating movem to mem. If FRAME_RELATED, notes
3294 are added that the dwarf2 machinery understands. */
3297 cris_emit_movem_store (rtx dest, rtx nregs_rtx, int increment,
3298 bool frame_related)
3300 int nregs = INTVAL (nregs_rtx);
3301 rtvec vec;
3302 int eltno = 1;
3303 int i;
3304 rtx insn;
3305 rtx destreg = XEXP (dest, 0);
3306 unsigned int regno = nregs - 1;
3307 int regno_inc = -1;
3309 if (TARGET_V32)
3311 regno = 0;
3312 regno_inc = 1;
3315 if (GET_CODE (destreg) == POST_INC)
3316 increment += nregs * 4;
3318 if (GET_CODE (destreg) == POST_INC || GET_CODE (destreg) == PLUS)
3319 destreg = XEXP (destreg, 0);
3321 CRIS_ASSERT (REG_P (destreg));
3323 /* Don't use movem for just one insn. The insns are equivalent except
3324 for the pipeline hazard (on v32); movem does not forward the loaded
3325 registers so there's a three cycles penalty for use. */
3326 if (nregs == 1)
3328 rtx mov = gen_rtx_SET (VOIDmode, dest, gen_rtx_REG (SImode, 0));
3330 if (increment == 0)
3332 insn = emit_insn (mov);
3333 if (frame_related)
3334 RTX_FRAME_RELATED_P (insn) = 1;
3335 return insn;
3338 /* If there was a request for a side-effect, create the ordinary
3339 parallel. */
3340 vec = rtvec_alloc (2);
3342 RTVEC_ELT (vec, 0) = mov;
3343 RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, destreg,
3344 plus_constant (destreg, increment));
3345 if (frame_related)
3347 RTX_FRAME_RELATED_P (mov) = 1;
3348 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3351 else
3353 vec = rtvec_alloc (nregs + (increment != 0 ? 1 : 0));
3354 RTVEC_ELT (vec, 0)
3355 = gen_rtx_SET (VOIDmode,
3356 replace_equiv_address (dest,
3357 plus_constant (destreg,
3358 increment)),
3359 gen_rtx_REG (SImode, regno));
3360 regno += regno_inc;
3362 /* The dwarf2 info wants this mark on each component in a parallel
3363 that's part of the prologue (though it's optional on the first
3364 component). */
3365 if (frame_related)
3366 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 0)) = 1;
3368 if (increment != 0)
3370 RTVEC_ELT (vec, 1)
3371 = gen_rtx_SET (VOIDmode, destreg,
3372 plus_constant (destreg,
3373 increment != 0
3374 ? increment : nregs * 4));
3375 eltno++;
3377 if (frame_related)
3378 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3380 /* Don't call adjust_address_nv on a post-incremented address if
3381 we can help it. */
3382 if (GET_CODE (XEXP (dest, 0)) == POST_INC)
3383 dest = replace_equiv_address (dest, destreg);
3386 for (i = 1; i < nregs; i++, eltno++)
3388 RTVEC_ELT (vec, eltno)
3389 = gen_rtx_SET (VOIDmode, adjust_address_nv (dest, SImode, i * 4),
3390 gen_rtx_REG (SImode, regno));
3391 if (frame_related)
3392 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, eltno)) = 1;
3393 regno += regno_inc;
3397 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, vec));
3399 /* Because dwarf2out.c handles the insns in a parallel as a sequence,
3400 we need to keep the stack adjustment separate, after the
3401 MEM-setters. Else the stack-adjustment in the second component of
3402 the parallel would be mishandled; the offsets for the SETs that
3403 follow it would be wrong. We prepare for this by adding a
3404 REG_FRAME_RELATED_EXPR with the MEM-setting parts in a SEQUENCE
3405 followed by the increment. Note that we have FRAME_RELATED_P on
3406 all the SETs, including the original stack adjustment SET in the
3407 parallel. */
3408 if (frame_related)
3410 if (increment != 0)
3412 rtx seq = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nregs + 1));
3413 XVECEXP (seq, 0, 0) = copy_rtx (XVECEXP (PATTERN (insn), 0, 0));
3414 for (i = 1; i < nregs; i++)
3415 XVECEXP (seq, 0, i)
3416 = copy_rtx (XVECEXP (PATTERN (insn), 0, i + 1));
3417 XVECEXP (seq, 0, nregs) = copy_rtx (XVECEXP (PATTERN (insn), 0, 1));
3418 REG_NOTES (insn)
3419 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, seq,
3420 REG_NOTES (insn));
3423 RTX_FRAME_RELATED_P (insn) = 1;
3426 return insn;
3429 /* Worker function for expanding the address for PIC function calls. */
3431 void
3432 cris_expand_pic_call_address (rtx *opp)
3434 rtx op = *opp;
3436 gcc_assert (MEM_P (op));
3437 op = XEXP (op, 0);
3439 /* It might be that code can be generated that jumps to 0 (or to a
3440 specific address). Don't die on that. (There is a
3441 testcase.) */
3442 if (CONSTANT_ADDRESS_P (op) && !CONST_INT_P (op))
3444 enum cris_pic_symbol_type t = cris_pic_symbol_type_of (op);
3446 CRIS_ASSERT (can_create_pseudo_p ());
3448 /* For local symbols (non-PLT), just get the plain symbol
3449 reference into a register. For symbols that can be PLT, make
3450 them PLT. */
3451 if (t == cris_rel_symbol)
3453 /* For v32, we're fine as-is; just PICify the symbol. Forcing
3454 into a register caused performance regression for 3.2.1,
3455 observable in __floatdidf and elsewhere in libgcc. */
3456 if (TARGET_V32)
3458 rtx sym = GET_CODE (op) != CONST ? op : get_related_value (op);
3459 HOST_WIDE_INT offs = get_integer_term (op);
3461 /* We can't get calls to sym+N, N integer, can we? */
3462 gcc_assert (offs == 0);
3464 op = gen_rtx_CONST (Pmode,
3465 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, sym),
3466 CRIS_UNSPEC_PCREL));
3468 else
3469 op = force_reg (Pmode, op);
3471 else if (t == cris_got_symbol)
3473 if (TARGET_AVOID_GOTPLT)
3475 /* Change a "jsr sym" into (allocate register rM, rO)
3476 "move.d (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_GOTREL)),rM"
3477 "add.d rPIC,rM,rO", "jsr rO" for pre-v32 and
3478 "jsr (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_PCREL))"
3479 for v32. */
3480 rtx tem, rm, ro;
3481 gcc_assert (can_create_pseudo_p ());
3482 current_function_uses_pic_offset_table = 1;
3483 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3484 TARGET_V32
3485 ? CRIS_UNSPEC_PLT_PCREL
3486 : CRIS_UNSPEC_PLT_GOTREL);
3487 tem = gen_rtx_CONST (Pmode, tem);
3488 if (TARGET_V32)
3489 op = tem;
3490 else
3492 rm = gen_reg_rtx (Pmode);
3493 emit_move_insn (rm, tem);
3494 ro = gen_reg_rtx (Pmode);
3495 if (expand_binop (Pmode, add_optab, rm,
3496 pic_offset_table_rtx,
3497 ro, 0, OPTAB_LIB_WIDEN) != ro)
3498 internal_error ("expand_binop failed in movsi got");
3499 op = ro;
3502 else
3504 /* Change a "jsr sym" into (allocate register rM, rO)
3505 "move.d (const (unspec [sym] CRIS_UNSPEC_PLTGOTREAD)),rM"
3506 "add.d rPIC,rM,rO" "jsr [rO]" with the memory access
3507 marked as not trapping and not aliasing. No "move.d
3508 [rO],rP" as that would invite to re-use of a value
3509 that should not be reused. FIXME: Need a peephole2
3510 for cases when this is cse:d from the call, to change
3511 back to just get the PLT entry address, so we don't
3512 resolve the same symbol over and over (the memory
3513 access of the PLTGOT isn't constant). */
3514 rtx tem, mem, rm, ro;
3516 gcc_assert (can_create_pseudo_p ());
3517 current_function_uses_pic_offset_table = 1;
3518 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3519 CRIS_UNSPEC_PLTGOTREAD);
3520 rm = gen_reg_rtx (Pmode);
3521 emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
3522 ro = gen_reg_rtx (Pmode);
3523 if (expand_binop (Pmode, add_optab, rm,
3524 pic_offset_table_rtx,
3525 ro, 0, OPTAB_LIB_WIDEN) != ro)
3526 internal_error ("expand_binop failed in movsi got");
3527 mem = gen_rtx_MEM (Pmode, ro);
3529 /* This MEM doesn't alias anything. Whether it aliases
3530 other same symbols is unimportant. */
3531 set_mem_alias_set (mem, new_alias_set ());
3532 MEM_NOTRAP_P (mem) = 1;
3533 op = mem;
3536 else
3537 /* Can't possibly get a GOT-needing-fixup for a function-call,
3538 right? */
3539 fatal_insn ("Unidentifiable call op", op);
3541 *opp = replace_equiv_address (*opp, op);
3545 /* Make sure operands are in the right order for an addsi3 insn as
3546 generated by a define_split. A MEM as the first operand isn't
3547 recognized by addsi3 after reload. OPERANDS contains the operands,
3548 with the first at OPERANDS[N] and the second at OPERANDS[N+1]. */
3550 void
3551 cris_order_for_addsi3 (rtx *operands, int n)
3553 if (MEM_P (operands[n]))
3555 rtx tem = operands[n];
3556 operands[n] = operands[n + 1];
3557 operands[n + 1] = tem;
3561 /* Use from within code, from e.g. PRINT_OPERAND and
3562 PRINT_OPERAND_ADDRESS. Macros used in output_addr_const need to emit
3563 different things depending on whether code operand or constant is
3564 emitted. */
3566 static void
3567 cris_output_addr_const (FILE *file, rtx x)
3569 in_code++;
3570 output_addr_const (file, x);
3571 in_code--;
3574 /* Worker function for ASM_OUTPUT_SYMBOL_REF. */
3576 void
3577 cris_asm_output_symbol_ref (FILE *file, rtx x)
3579 gcc_assert (GET_CODE (x) == SYMBOL_REF);
3581 if (flag_pic && in_code > 0)
3583 const char *origstr = XSTR (x, 0);
3584 const char *str;
3585 str = (* targetm.strip_name_encoding) (origstr);
3586 assemble_name (file, str);
3588 /* Sanity check. */
3589 if (!TARGET_V32 && !current_function_uses_pic_offset_table)
3590 output_operand_lossage ("PIC register isn't set up");
3592 else
3593 assemble_name (file, XSTR (x, 0));
3596 /* Worker function for ASM_OUTPUT_LABEL_REF. */
3598 void
3599 cris_asm_output_label_ref (FILE *file, char *buf)
3601 if (flag_pic && in_code > 0)
3603 assemble_name (file, buf);
3605 /* Sanity check. */
3606 if (!TARGET_V32 && !current_function_uses_pic_offset_table)
3607 internal_error ("emitting PIC operand, but PIC register isn't set up");
3609 else
3610 assemble_name (file, buf);
3613 /* Worker function for OUTPUT_ADDR_CONST_EXTRA. */
3615 bool
3616 cris_output_addr_const_extra (FILE *file, rtx xconst)
3618 switch (GET_CODE (xconst))
3620 rtx x;
3622 case UNSPEC:
3623 x = XVECEXP (xconst, 0, 0);
3624 CRIS_ASSERT (GET_CODE (x) == SYMBOL_REF
3625 || GET_CODE (x) == LABEL_REF
3626 || GET_CODE (x) == CONST);
3627 output_addr_const (file, x);
3628 switch (XINT (xconst, 1))
3630 case CRIS_UNSPEC_PCREL:
3631 /* We only get this with -fpic/PIC to tell it apart from an
3632 invalid symbol. We can't tell here, but it should only
3633 be the operand of a call or movsi. */
3634 gcc_assert (TARGET_V32 && flag_pic);
3635 break;
3637 case CRIS_UNSPEC_PLT_PCREL:
3638 gcc_assert (TARGET_V32);
3639 fprintf (file, ":PLT");
3640 break;
3642 case CRIS_UNSPEC_PLT_GOTREL:
3643 gcc_assert (!TARGET_V32);
3644 fprintf (file, ":PLTG");
3645 break;
3647 case CRIS_UNSPEC_GOTREL:
3648 gcc_assert (!TARGET_V32);
3649 fprintf (file, ":GOTOFF");
3650 break;
3652 case CRIS_UNSPEC_GOTREAD:
3653 if (flag_pic == 1)
3654 fprintf (file, ":GOT16");
3655 else
3656 fprintf (file, ":GOT");
3657 break;
3659 case CRIS_UNSPEC_PLTGOTREAD:
3660 if (flag_pic == 1)
3661 fprintf (file, CRIS_GOTPLT_SUFFIX "16");
3662 else
3663 fprintf (file, CRIS_GOTPLT_SUFFIX);
3664 break;
3666 default:
3667 gcc_unreachable ();
3669 return true;
3671 default:
3672 return false;
3676 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3678 static rtx
3679 cris_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3680 int incoming ATTRIBUTE_UNUSED)
3682 return gen_rtx_REG (Pmode, CRIS_STRUCT_VALUE_REGNUM);
3685 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3687 static void
3688 cris_setup_incoming_varargs (CUMULATIVE_ARGS *ca,
3689 enum machine_mode mode ATTRIBUTE_UNUSED,
3690 tree type ATTRIBUTE_UNUSED,
3691 int *pretend_arg_size,
3692 int second_time)
3694 if (ca->regs < CRIS_MAX_ARGS_IN_REGS)
3696 int stdarg_regs = CRIS_MAX_ARGS_IN_REGS - ca->regs;
3697 cfun->machine->stdarg_regs = stdarg_regs;
3698 *pretend_arg_size = stdarg_regs * 4;
3701 if (TARGET_PDEBUG)
3702 fprintf (asm_out_file,
3703 "\n; VA:: ANSI: %d args before, anon @ #%d, %dtime\n",
3704 ca->regs, *pretend_arg_size, second_time);
3707 /* Return true if TYPE must be passed by invisible reference.
3708 For cris, we pass <= 8 bytes by value, others by reference. */
3710 static bool
3711 cris_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
3712 enum machine_mode mode, const_tree type,
3713 bool named ATTRIBUTE_UNUSED)
3715 return (targetm.calls.must_pass_in_stack (mode, type)
3716 || CRIS_FUNCTION_ARG_SIZE (mode, type) > 8);
3720 static int
3721 cris_arg_partial_bytes (CUMULATIVE_ARGS *ca, enum machine_mode mode,
3722 tree type, bool named ATTRIBUTE_UNUSED)
3724 if (ca->regs == CRIS_MAX_ARGS_IN_REGS - 1
3725 && !targetm.calls.must_pass_in_stack (mode, type)
3726 && CRIS_FUNCTION_ARG_SIZE (mode, type) > 4
3727 && CRIS_FUNCTION_ARG_SIZE (mode, type) <= 8)
3728 return UNITS_PER_WORD;
3729 else
3730 return 0;
3733 /* Worker function for TARGET_MD_ASM_CLOBBERS. */
3735 static tree
3736 cris_md_asm_clobbers (tree outputs, tree inputs, tree in_clobbers)
3738 HARD_REG_SET mof_set;
3739 tree clobbers;
3740 tree t;
3742 CLEAR_HARD_REG_SET (mof_set);
3743 SET_HARD_REG_BIT (mof_set, CRIS_MOF_REGNUM);
3745 /* For the time being, all asms clobber condition codes. Revisit when
3746 there's a reasonable use for inputs/outputs that mention condition
3747 codes. */
3748 clobbers
3749 = tree_cons (NULL_TREE,
3750 build_string (strlen (reg_names[CRIS_CC0_REGNUM]),
3751 reg_names[CRIS_CC0_REGNUM]),
3752 in_clobbers);
3754 for (t = outputs; t != NULL; t = TREE_CHAIN (t))
3756 tree val = TREE_VALUE (t);
3758 /* The constraint letter for the singleton register class of MOF
3759 is 'h'. If it's mentioned in the constraints, the asm is
3760 MOF-aware and adding it to the clobbers would cause it to have
3761 impossible constraints. */
3762 if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
3763 'h') != NULL
3764 || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
3765 return clobbers;
3768 for (t = inputs; t != NULL; t = TREE_CHAIN (t))
3770 tree val = TREE_VALUE (t);
3772 if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
3773 'h') != NULL
3774 || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
3775 return clobbers;
3778 return tree_cons (NULL_TREE,
3779 build_string (strlen (reg_names[CRIS_MOF_REGNUM]),
3780 reg_names[CRIS_MOF_REGNUM]),
3781 clobbers);
3784 #if 0
3785 /* Various small functions to replace macros. Only called from a
3786 debugger. They might collide with gcc functions or system functions,
3787 so only emit them when '#if 1' above. */
3789 enum rtx_code Get_code (rtx);
3791 enum rtx_code
3792 Get_code (rtx x)
3794 return GET_CODE (x);
3797 const char *Get_mode (rtx);
3799 const char *
3800 Get_mode (rtx x)
3802 return GET_MODE_NAME (GET_MODE (x));
3805 rtx Xexp (rtx, int);
3808 Xexp (rtx x, int n)
3810 return XEXP (x, n);
3813 rtx Xvecexp (rtx, int, int);
3816 Xvecexp (rtx x, int n, int m)
3818 return XVECEXP (x, n, m);
3821 int Get_rtx_len (rtx);
3824 Get_rtx_len (rtx x)
3826 return GET_RTX_LENGTH (GET_CODE (x));
3829 /* Use upper-case to distinguish from local variables that are sometimes
3830 called next_insn and prev_insn. */
3832 rtx Next_insn (rtx);
3835 Next_insn (rtx insn)
3837 return NEXT_INSN (insn);
3840 rtx Prev_insn (rtx);
3843 Prev_insn (rtx insn)
3845 return PREV_INSN (insn);
3847 #endif
3849 #include "gt-cris.h"
3852 * Local variables:
3853 * eval: (c-set-style "gnu")
3854 * indent-tabs-mode: t
3855 * End: