Merge cond-optab branch.
[official-gcc.git] / gcc / config / cris / cris.c
blobbc634ddbf3ed9138e884dbf3485015e2ced10c97
1 /* Definitions for GCC. Part of the machine description for CRIS.
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 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 GTY(()) machine_function
68 int needs_return_address_on_stack;
70 /* This is the number of registers we save in the prologue due to
71 stdarg. */
72 int stdarg_regs;
74 enum cris_retinsn_type return_type;
77 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
78 pattern. */
79 static char cris_output_insn_is_bound = 0;
81 /* In code for output macros, this is how we know whether e.g. constant
82 goes in code or in a static initializer. */
83 static int in_code = 0;
85 /* Fix for reg_overlap_mentioned_p. */
86 static int cris_reg_overlap_mentioned_p (rtx, rtx);
88 static 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 *, bool);
116 static int cris_address_cost (rtx, bool);
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 crtl->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 crtl->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 || (crtl->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 || !CRIS_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 (crtl->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 += crtl->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;
1435 if (GET_CODE (SET_SRC (exp)) == COMPARE
1436 && XEXP (SET_SRC (exp), 1) == const0_rtx)
1437 cc_status.value1 = XEXP (SET_SRC (exp), 0);
1438 else
1439 cc_status.value1 = SET_SRC (exp);
1441 /* Handle flags for the special btstq on one bit. */
1442 if (GET_CODE (cc_status.value1) == ZERO_EXTRACT
1443 && XEXP (cc_status.value1, 1) == const1_rtx)
1445 if (CONST_INT_P (XEXP (cc_status.value1, 0)))
1446 /* Using cmpq. */
1447 cc_status.flags = CC_INVERTED;
1448 else
1449 /* A one-bit btstq. */
1450 cc_status.flags = CC_Z_IN_NOT_N;
1453 else if (GET_CODE (SET_SRC (exp)) == COMPARE)
1455 if (!REG_P (XEXP (SET_SRC (exp), 0))
1456 && XEXP (SET_SRC (exp), 1) != const0_rtx)
1457 /* For some reason gcc will not canonicalize compare
1458 operations, reversing the sign by itself if
1459 operands are in wrong order. */
1460 /* (But NOT inverted; eq is still eq.) */
1461 cc_status.flags = CC_REVERSED;
1463 /* This seems to be overlooked by gcc. FIXME: Check again.
1464 FIXME: Is it really safe? */
1465 cc_status.value2
1466 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1467 XEXP (SET_SRC (exp), 0),
1468 XEXP (SET_SRC (exp), 1));
1470 return;
1472 else if (REG_P (SET_DEST (exp))
1473 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1474 && REG_P (XEXP (SET_DEST (exp), 0))))
1476 /* A register is set; normally CC is set to show that no
1477 test insn is needed. Catch the exceptions. */
1479 /* If not to cc0, then no "set"s in non-natural mode give
1480 ok cc0... */
1481 if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1482 || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1484 /* ... except add:s and sub:s in DImode. */
1485 if (GET_MODE (SET_DEST (exp)) == DImode
1486 && (GET_CODE (SET_SRC (exp)) == PLUS
1487 || GET_CODE (SET_SRC (exp)) == MINUS))
1489 CC_STATUS_INIT;
1490 cc_status.value1 = SET_DEST (exp);
1491 cc_status.value2 = SET_SRC (exp);
1493 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1494 cc_status.value2))
1495 cc_status.value2 = 0;
1497 /* Add and sub may set V, which gets us
1498 unoptimizable results in "gt" and "le" condition
1499 codes. */
1500 cc_status.flags |= CC_NO_OVERFLOW;
1502 return;
1505 else if (SET_SRC (exp) == const0_rtx
1506 || (REG_P (SET_SRC (exp))
1507 && (REGNO (SET_SRC (exp))
1508 > CRIS_LAST_GENERAL_REGISTER))
1509 || (TARGET_V32
1510 && GET_CODE (SET_SRC (exp)) == CONST_INT
1511 && CRIS_CONST_OK_FOR_LETTER_P (INTVAL (SET_SRC (exp)),
1512 'I')))
1514 /* There's no CC0 change for this case. Just check
1515 for overlap. */
1516 if (cc_status.value1
1517 && modified_in_p (cc_status.value1, insn))
1518 cc_status.value1 = 0;
1520 if (cc_status.value2
1521 && modified_in_p (cc_status.value2, insn))
1522 cc_status.value2 = 0;
1524 return;
1526 else
1528 CC_STATUS_INIT;
1529 cc_status.value1 = SET_DEST (exp);
1530 cc_status.value2 = SET_SRC (exp);
1532 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1533 cc_status.value2))
1534 cc_status.value2 = 0;
1536 /* Some operations may set V, which gets us
1537 unoptimizable results in "gt" and "le" condition
1538 codes. */
1539 if (GET_CODE (SET_SRC (exp)) == PLUS
1540 || GET_CODE (SET_SRC (exp)) == MINUS
1541 || GET_CODE (SET_SRC (exp)) == NEG)
1542 cc_status.flags |= CC_NO_OVERFLOW;
1544 /* For V32, nothing with a register destination sets
1545 C and V usefully. */
1546 if (TARGET_V32)
1547 cc_status.flags |= CC_NO_OVERFLOW;
1549 return;
1552 else if (MEM_P (SET_DEST (exp))
1553 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1554 && MEM_P (XEXP (SET_DEST (exp), 0))))
1556 /* When SET to MEM, then CC is not changed (except for
1557 overlap). */
1558 if (cc_status.value1
1559 && modified_in_p (cc_status.value1, insn))
1560 cc_status.value1 = 0;
1562 if (cc_status.value2
1563 && modified_in_p (cc_status.value2, insn))
1564 cc_status.value2 = 0;
1566 return;
1569 else if (GET_CODE (exp) == PARALLEL)
1571 if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1572 && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1573 && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1575 if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1576 && MEM_P (XEXP (XVECEXP (exp, 0, 0), 1)))
1578 CC_STATUS_INIT;
1580 /* For "move.S [rx=ry+o],rz", say CC reflects
1581 value1=rz and value2=[rx] */
1582 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1583 cc_status.value2
1584 = replace_equiv_address (XEXP (XVECEXP (exp, 0, 0), 1),
1585 XEXP (XVECEXP (exp, 0, 1), 0));
1587 /* Huh? A side-effect cannot change the destination
1588 register. */
1589 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1590 cc_status.value2))
1591 internal_error ("internal error: sideeffect-insn affecting main effect");
1593 /* For V32, moves to registers don't set C and V. */
1594 if (TARGET_V32)
1595 cc_status.flags |= CC_NO_OVERFLOW;
1596 return;
1598 else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1599 || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1600 && MEM_P (XEXP (XVECEXP (exp, 0, 0), 0)))
1602 /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1603 say flags are not changed, except for overlap. */
1604 if (cc_status.value1
1605 && modified_in_p (cc_status.value1, insn))
1606 cc_status.value1 = 0;
1608 if (cc_status.value2
1609 && modified_in_p (cc_status.value2, insn))
1610 cc_status.value2 = 0;
1612 return;
1617 /* If we got here, the case wasn't covered by the code above. */
1618 CC_STATUS_INIT;
1621 /* This function looks into the pattern to see how this insn affects
1622 condition codes.
1624 Used when to eliminate test insns before a condition-code user,
1625 such as a "scc" insn or a conditional branch. This includes
1626 checking if the entities that cc was updated by, are changed by the
1627 operation.
1629 Currently a jumble of the old peek-inside-the-insn and the newer
1630 check-cc-attribute methods. */
1632 void
1633 cris_notice_update_cc (rtx exp, rtx insn)
1635 enum attr_cc attrval = get_attr_cc (insn);
1637 /* Check if user specified "-mcc-init" as a bug-workaround. Remember
1638 to still set CC_REVERSED as below, since that's required by some
1639 compare insn alternatives. (FIXME: GCC should do this virtual
1640 operand swap by itself.) A test-case that may otherwise fail is
1641 gcc.c-torture/execute/20000217-1.c -O0 and -O1. */
1642 if (TARGET_CCINIT)
1644 CC_STATUS_INIT;
1646 if (attrval == CC_REV)
1647 cc_status.flags = CC_REVERSED;
1648 return;
1651 /* Slowly, we're converting to using attributes to control the setting
1652 of condition-code status. */
1653 switch (attrval)
1655 case CC_NONE:
1656 /* Even if it is "none", a setting may clobber a previous
1657 cc-value, so check. */
1658 if (GET_CODE (exp) == SET)
1660 if (cc_status.value1
1661 && modified_in_p (cc_status.value1, insn))
1662 cc_status.value1 = 0;
1664 if (cc_status.value2
1665 && modified_in_p (cc_status.value2, insn))
1666 cc_status.value2 = 0;
1668 return;
1670 case CC_CLOBBER:
1671 CC_STATUS_INIT;
1672 return;
1674 case CC_REV:
1675 case CC_NOOV32:
1676 case CC_NORMAL:
1677 cris_normal_notice_update_cc (exp, insn);
1679 /* The "test" insn doesn't clear (carry and) overflow on V32. We
1680 can change bge => bpl and blt => bmi by passing on to the cc0
1681 user that V should not be considered; bgt and ble are taken
1682 care of by other methods (see {tst,cmp}{si,hi,qi}). */
1683 if (attrval == CC_NOOV32 && TARGET_V32)
1684 cc_status.flags |= CC_NO_OVERFLOW;
1685 return;
1687 default:
1688 internal_error ("unknown cc_attr value");
1691 CC_STATUS_INIT;
1694 /* Return != 0 if the return sequence for the current function is short,
1695 like "ret" or "jump [sp+]". Prior to reloading, we can't tell if
1696 registers must be saved, so return 0 then. */
1698 bool
1699 cris_simple_epilogue (void)
1701 unsigned int regno;
1702 unsigned int reglimit = STACK_POINTER_REGNUM;
1703 bool got_really_used = false;
1705 if (! reload_completed
1706 || frame_pointer_needed
1707 || get_frame_size () != 0
1708 || crtl->args.pretend_args_size
1709 || crtl->args.size
1710 || crtl->outgoing_args_size
1711 || crtl->calls_eh_return
1713 /* If we're not supposed to emit prologue and epilogue, we must
1714 not emit return-type instructions. */
1715 || !TARGET_PROLOGUE_EPILOGUE)
1716 return false;
1718 /* Can't return from stacked return address with v32. */
1719 if (TARGET_V32 && cris_return_address_on_stack ())
1720 return false;
1722 if (crtl->uses_pic_offset_table)
1724 push_topmost_sequence ();
1725 got_really_used
1726 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
1727 pop_topmost_sequence ();
1730 /* No simple epilogue if there are saved registers. */
1731 for (regno = 0; regno < reglimit; regno++)
1732 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1733 return false;
1735 return true;
1738 /* Expand a return insn (just one insn) marked as using SRP or stack
1739 slot depending on parameter ON_STACK. */
1741 void
1742 cris_expand_return (bool on_stack)
1744 /* FIXME: emit a parallel with a USE for SRP or the stack-slot, to
1745 tell "ret" from "jump [sp+]". Some, but not all, other parts of
1746 GCC expect just (return) to do the right thing when optimizing, so
1747 we do that until they're fixed. Currently, all return insns in a
1748 function must be the same (not really a limiting factor) so we need
1749 to check that it doesn't change half-way through. */
1750 emit_jump_insn (gen_rtx_RETURN (VOIDmode));
1752 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_RET || !on_stack);
1753 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_JUMP || on_stack);
1755 cfun->machine->return_type
1756 = on_stack ? CRIS_RETINSN_JUMP : CRIS_RETINSN_RET;
1759 /* Compute a (partial) cost for rtx X. Return true if the complete
1760 cost has been computed, and false if subexpressions should be
1761 scanned. In either case, *TOTAL contains the cost result. */
1763 static bool
1764 cris_rtx_costs (rtx x, int code, int outer_code, int *total,
1765 bool speed)
1767 switch (code)
1769 case CONST_INT:
1771 HOST_WIDE_INT val = INTVAL (x);
1772 if (val == 0)
1773 *total = 0;
1774 else if (val < 32 && val >= -32)
1775 *total = 1;
1776 /* Eight or 16 bits are a word and cycle more expensive. */
1777 else if (val <= 32767 && val >= -32768)
1778 *total = 2;
1779 /* A 32-bit constant (or very seldom, unsigned 16 bits) costs
1780 another word. FIXME: This isn't linear to 16 bits. */
1781 else
1782 *total = 4;
1783 return true;
1786 case LABEL_REF:
1787 *total = 6;
1788 return true;
1790 case CONST:
1791 case SYMBOL_REF:
1792 *total = 6;
1793 return true;
1795 case CONST_DOUBLE:
1796 if (x != CONST0_RTX (GET_MODE (x) == VOIDmode ? DImode : GET_MODE (x)))
1797 *total = 12;
1798 else
1799 /* Make 0.0 cheap, else test-insns will not be used. */
1800 *total = 0;
1801 return true;
1803 case MULT:
1804 /* If we have one arm of an ADDI, make sure it gets the cost of
1805 one insn, i.e. zero cost for this operand, and just the cost
1806 of the PLUS, as the insn is created by combine from a PLUS
1807 and an ASHIFT, and the MULT cost below would make the
1808 combined value be larger than the separate insns. The insn
1809 validity is checked elsewhere by combine.
1811 FIXME: this case is a stop-gap for 4.3 and 4.4, this whole
1812 function should be rewritten. */
1813 if (outer_code == PLUS && BIAP_INDEX_P (x))
1815 *total = 0;
1816 return true;
1819 /* Identify values that are no powers of two. Powers of 2 are
1820 taken care of already and those values should not be changed. */
1821 if (!CONST_INT_P (XEXP (x, 1))
1822 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1824 /* If we have a multiply insn, then the cost is between
1825 1 and 2 "fast" instructions. */
1826 if (TARGET_HAS_MUL_INSNS)
1828 *total = COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2;
1829 return true;
1832 /* Estimate as 4 + 4 * #ofbits. */
1833 *total = COSTS_N_INSNS (132);
1834 return true;
1836 return false;
1838 case UDIV:
1839 case MOD:
1840 case UMOD:
1841 case DIV:
1842 if (!CONST_INT_P (XEXP (x, 1))
1843 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1845 /* Estimate this as 4 + 8 * #of bits. */
1846 *total = COSTS_N_INSNS (260);
1847 return true;
1849 return false;
1851 case AND:
1852 if (CONST_INT_P (XEXP (x, 1))
1853 /* Two constants may actually happen before optimization. */
1854 && !CONST_INT_P (XEXP (x, 0))
1855 && !CRIS_CONST_OK_FOR_LETTER_P (INTVAL (XEXP (x, 1)), 'I'))
1857 *total = (rtx_cost (XEXP (x, 0), outer_code, speed) + 2
1858 + 2 * GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))));
1859 return true;
1861 return false;
1863 case ZERO_EXTRACT:
1864 if (outer_code != COMPARE)
1865 return false;
1866 /* fall through */
1868 case ZERO_EXTEND: case SIGN_EXTEND:
1869 *total = rtx_cost (XEXP (x, 0), outer_code, speed);
1870 return true;
1872 default:
1873 return false;
1877 /* The ADDRESS_COST worker. */
1879 static int
1880 cris_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
1882 /* The metric to use for the cost-macros is unclear.
1883 The metric used here is (the number of cycles needed) / 2,
1884 where we consider equal a cycle for a word of code and a cycle to
1885 read memory. FIXME: Adding "+ 1" to all values would avoid
1886 returning 0, as tree-ssa-loop-ivopts.c as of r128272 "normalizes"
1887 0 to 1, thereby giving equal costs to [rN + rM] and [rN].
1888 Unfortunately(?) such a hack would expose other pessimizations,
1889 at least with g++.dg/tree-ssa/ivopts-1.C, adding insns to the
1890 loop there, without apparent reason. */
1892 /* The cheapest addressing modes get 0, since nothing extra is needed. */
1893 if (BASE_OR_AUTOINCR_P (x))
1894 return 0;
1896 /* An indirect mem must be a DIP. This means two bytes extra for code,
1897 and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */
1898 if (MEM_P (x))
1899 return (2 + 4) / 2;
1901 /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
1902 an extra DIP prefix and 4 bytes of constant in most cases. */
1903 if (CONSTANT_P (x))
1904 return (2 + 4) / 2;
1906 /* Handle BIAP and BDAP prefixes. */
1907 if (GET_CODE (x) == PLUS)
1909 rtx tem1 = XEXP (x, 0);
1910 rtx tem2 = XEXP (x, 1);
1912 /* Local extended canonicalization rule: the first operand must
1913 be REG, unless it's an operation (MULT). */
1914 if (!REG_P (tem1) && GET_CODE (tem1) != MULT)
1915 tem1 = tem2, tem2 = XEXP (x, 0);
1917 /* We'll "assume" we have canonical RTX now. */
1918 gcc_assert (REG_P (tem1) || GET_CODE (tem1) == MULT);
1920 /* A BIAP is 2 extra bytes for the prefix insn, nothing more. We
1921 recognize the typical MULT which is always in tem1 because of
1922 insn canonicalization. */
1923 if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
1924 || REG_P (tem2))
1925 return 2 / 2;
1927 /* A BDAP (quick) is 2 extra bytes. Any constant operand to the
1928 PLUS is always found in tem2. */
1929 if (CONST_INT_P (tem2) && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
1930 return 2 / 2;
1932 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
1933 bytes. */
1934 if (CONST_INT_P (tem2)
1935 && CRIS_CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
1936 return (2 + 2) / 2;
1938 /* A BDAP with some other constant is 2 bytes extra. */
1939 if (CONSTANT_P (tem2))
1940 return (2 + 2 + 2) / 2;
1942 /* BDAP with something indirect should have a higher cost than
1943 BIAP with register. FIXME: Should it cost like a MEM or more? */
1944 return (2 + 2 + 2) / 2;
1947 /* What else? Return a high cost. It matters only for valid
1948 addressing modes. */
1949 return 10;
1952 /* Check various objections to the side-effect. Used in the test-part
1953 of an anonymous insn describing an insn with a possible side-effect.
1954 Returns nonzero if the implied side-effect is ok.
1956 code : PLUS or MULT
1957 ops : An array of rtx:es. lreg, rreg, rval,
1958 The variables multop and other_op are indexes into this,
1959 or -1 if they are not applicable.
1960 lreg : The register that gets assigned in the side-effect.
1961 rreg : One register in the side-effect expression
1962 rval : The other register, or an int.
1963 multop : An integer to multiply rval with.
1964 other_op : One of the entities of the main effect,
1965 whose mode we must consider. */
1968 cris_side_effect_mode_ok (enum rtx_code code, rtx *ops,
1969 int lreg, int rreg, int rval,
1970 int multop, int other_op)
1972 /* Find what value to multiply with, for rx =ry + rz * n. */
1973 int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
1975 rtx reg_rtx = ops[rreg];
1976 rtx val_rtx = ops[rval];
1978 /* The operands may be swapped. Canonicalize them in reg_rtx and
1979 val_rtx, where reg_rtx always is a reg (for this constraint to
1980 match). */
1981 if (! BASE_P (reg_rtx))
1982 reg_rtx = val_rtx, val_rtx = ops[rreg];
1984 /* Don't forget to check that reg_rtx really is a reg. If it isn't,
1985 we have no business. */
1986 if (! BASE_P (reg_rtx))
1987 return 0;
1989 /* Don't do this when -mno-split. */
1990 if (!TARGET_SIDE_EFFECT_PREFIXES)
1991 return 0;
1993 /* The mult expression may be hidden in lreg. FIXME: Add more
1994 commentary about that. */
1995 if (GET_CODE (val_rtx) == MULT)
1997 mult = INTVAL (XEXP (val_rtx, 1));
1998 val_rtx = XEXP (val_rtx, 0);
1999 code = MULT;
2002 /* First check the "other operand". */
2003 if (other_op >= 0)
2005 if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
2006 return 0;
2008 /* Check if the lvalue register is the same as the "other
2009 operand". If so, the result is undefined and we shouldn't do
2010 this. FIXME: Check again. */
2011 if ((BASE_P (ops[lreg])
2012 && BASE_P (ops[other_op])
2013 && REGNO (ops[lreg]) == REGNO (ops[other_op]))
2014 || rtx_equal_p (ops[other_op], ops[lreg]))
2015 return 0;
2018 /* Do not accept frame_pointer_rtx as any operand. */
2019 if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
2020 || ops[rval] == frame_pointer_rtx
2021 || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
2022 return 0;
2024 if (code == PLUS
2025 && ! BASE_P (val_rtx))
2028 /* Do not allow rx = rx + n if a normal add or sub with same size
2029 would do. */
2030 if (rtx_equal_p (ops[lreg], reg_rtx)
2031 && CONST_INT_P (val_rtx)
2032 && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2033 return 0;
2035 /* Check allowed cases, like [r(+)?].[bwd] and const. */
2036 if (CONSTANT_P (val_rtx))
2037 return 1;
2039 if (MEM_P (val_rtx) && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
2040 return 1;
2042 if (GET_CODE (val_rtx) == SIGN_EXTEND
2043 && MEM_P (XEXP (val_rtx, 0))
2044 && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
2045 return 1;
2047 /* If we got here, it's not a valid addressing mode. */
2048 return 0;
2050 else if (code == MULT
2051 || (code == PLUS && BASE_P (val_rtx)))
2053 /* Do not allow rx = rx + ry.S, since it doesn't give better code. */
2054 if (rtx_equal_p (ops[lreg], reg_rtx)
2055 || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2056 return 0;
2058 /* Do not allow bad multiply-values. */
2059 if (mult != 1 && mult != 2 && mult != 4)
2060 return 0;
2062 /* Only allow r + ... */
2063 if (! BASE_P (reg_rtx))
2064 return 0;
2066 /* If we got here, all seems ok.
2067 (All checks need to be done above). */
2068 return 1;
2071 /* If we get here, the caller got its initial tests wrong. */
2072 internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
2075 /* Whether next_cc0_user of insn is LE or GT or requires a real compare
2076 insn for other reasons. */
2078 bool
2079 cris_cc0_user_requires_cmp (rtx insn)
2081 rtx cc0_user = NULL;
2082 rtx body;
2083 rtx set;
2085 gcc_assert (insn != NULL);
2087 if (!TARGET_V32)
2088 return false;
2090 cc0_user = next_cc0_user (insn);
2091 if (cc0_user == NULL)
2092 return false;
2094 body = PATTERN (cc0_user);
2095 set = single_set (cc0_user);
2097 /* Users can be sCC and bCC. */
2098 if (JUMP_P (cc0_user)
2099 && GET_CODE (body) == SET
2100 && SET_DEST (body) == pc_rtx
2101 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2102 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx)
2104 return
2105 GET_CODE (XEXP (SET_SRC (body), 0)) == GT
2106 || GET_CODE (XEXP (SET_SRC (body), 0)) == LE;
2108 else if (set)
2110 return
2111 GET_CODE (SET_SRC (body)) == GT
2112 || GET_CODE (SET_SRC (body)) == LE;
2115 gcc_unreachable ();
2118 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2119 does not handle the case where the IN operand is strict_low_part; it
2120 does handle it for X. Test-case in Axis-20010516. This function takes
2121 care of that for THIS port. FIXME: strict_low_part is going away
2122 anyway. */
2124 static int
2125 cris_reg_overlap_mentioned_p (rtx x, rtx in)
2127 /* The function reg_overlap_mentioned now handles when X is
2128 strict_low_part, but not when IN is a STRICT_LOW_PART. */
2129 if (GET_CODE (in) == STRICT_LOW_PART)
2130 in = XEXP (in, 0);
2132 return reg_overlap_mentioned_p (x, in);
2135 /* The TARGET_ASM_NAMED_SECTION worker.
2136 We just dispatch to the functions for ELF and a.out. */
2138 void
2139 cris_target_asm_named_section (const char *name, unsigned int flags,
2140 tree decl)
2142 if (! TARGET_ELF)
2143 default_no_named_section (name, flags, decl);
2144 else
2145 default_elf_asm_named_section (name, flags, decl);
2148 /* Return TRUE iff X is a CONST valid for e.g. indexing.
2149 ANY_OPERAND is 0 if X is in a CALL_P insn or movsi, 1
2150 elsewhere. */
2152 bool
2153 cris_valid_pic_const (rtx x, bool any_operand)
2155 gcc_assert (flag_pic);
2157 switch (GET_CODE (x))
2159 case CONST_INT:
2160 case CONST_DOUBLE:
2161 return true;
2162 default:
2166 if (GET_CODE (x) != CONST)
2167 return false;
2169 x = XEXP (x, 0);
2171 /* Handle (const (plus (unspec .. UNSPEC_GOTREL) (const_int ...))). */
2172 if (GET_CODE (x) == PLUS
2173 && GET_CODE (XEXP (x, 0)) == UNSPEC
2174 && (XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREL
2175 || XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_PCREL)
2176 && CONST_INT_P (XEXP (x, 1)))
2177 x = XEXP (x, 0);
2179 if (GET_CODE (x) == UNSPEC)
2180 switch (XINT (x, 1))
2182 /* A PCREL operand is only valid for call and movsi. */
2183 case CRIS_UNSPEC_PLT_PCREL:
2184 case CRIS_UNSPEC_PCREL:
2185 return !any_operand;
2187 case CRIS_UNSPEC_PLT_GOTREL:
2188 case CRIS_UNSPEC_PLTGOTREAD:
2189 case CRIS_UNSPEC_GOTREAD:
2190 case CRIS_UNSPEC_GOTREL:
2191 return true;
2192 default:
2193 gcc_unreachable ();
2196 return cris_pic_symbol_type_of (x) == cris_no_symbol;
2199 /* Helper function to find the right PIC-type symbol to generate,
2200 given the original (non-PIC) representation. */
2202 enum cris_pic_symbol_type
2203 cris_pic_symbol_type_of (rtx x)
2205 switch (GET_CODE (x))
2207 case SYMBOL_REF:
2208 return SYMBOL_REF_LOCAL_P (x)
2209 ? cris_rel_symbol : cris_got_symbol;
2211 case LABEL_REF:
2212 return cris_rel_symbol;
2214 case CONST:
2215 return cris_pic_symbol_type_of (XEXP (x, 0));
2217 case PLUS:
2218 case MINUS:
2220 enum cris_pic_symbol_type t1 = cris_pic_symbol_type_of (XEXP (x, 0));
2221 enum cris_pic_symbol_type t2 = cris_pic_symbol_type_of (XEXP (x, 1));
2223 gcc_assert (t1 == cris_no_symbol || t2 == cris_no_symbol);
2225 if (t1 == cris_got_symbol || t1 == cris_got_symbol)
2226 return cris_got_symbol_needing_fixup;
2228 return t1 != cris_no_symbol ? t1 : t2;
2231 case CONST_INT:
2232 case CONST_DOUBLE:
2233 return cris_no_symbol;
2235 case UNSPEC:
2236 /* Likely an offsettability-test attempting to add a constant to
2237 a GOTREAD symbol, which can't be handled. */
2238 return cris_invalid_pic_symbol;
2240 default:
2241 fatal_insn ("unrecognized supposed constant", x);
2244 gcc_unreachable ();
2247 /* The LEGITIMATE_PIC_OPERAND_P worker. */
2250 cris_legitimate_pic_operand (rtx x)
2252 /* Symbols are not valid PIC operands as-is; just constants. */
2253 return cris_valid_pic_const (x, true);
2256 /* The ASM_OUTPUT_CASE_END worker. */
2258 void
2259 cris_asm_output_case_end (FILE *stream, int num, rtx table)
2261 if (TARGET_V32)
2263 rtx whole_jump_insn = PATTERN (PREV_INSN (PREV_INSN (table)));
2265 /* This can be a SEQUENCE, meaning the delay-slot of the jump is
2266 filled. */
2267 rtx parallel_jump
2268 = (GET_CODE (whole_jump_insn) == SEQUENCE
2269 ? PATTERN (XVECEXP (whole_jump_insn, 0, 0)) : whole_jump_insn);
2271 asm_fprintf (stream,
2272 "\t.word %LL%d-.%s\n",
2273 CODE_LABEL_NUMBER (XEXP (XEXP (XEXP (XVECEXP
2274 (parallel_jump, 0, 0),
2275 1), 2), 0)),
2276 (TARGET_PDEBUG ? "; default" : ""));
2277 return;
2280 asm_fprintf (stream,
2281 "\t.word %LL%d-%LL%d%s\n",
2282 CODE_LABEL_NUMBER (XEXP
2283 (XEXP
2284 (XEXP
2285 (XVECEXP
2286 (PATTERN
2287 (PREV_INSN
2288 (PREV_INSN (table))), 0, 0), 1),
2289 2), 0)),
2290 num,
2291 (TARGET_PDEBUG ? "; default" : ""));
2294 /* TARGET_HANDLE_OPTION worker. We just store the values into local
2295 variables here. Checks for correct semantics are in
2296 cris_override_options. */
2298 static bool
2299 cris_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED,
2300 int value ATTRIBUTE_UNUSED)
2302 switch (code)
2304 case OPT_metrax100:
2305 target_flags
2306 |= (MASK_SVINTO
2307 + MASK_ETRAX4_ADD
2308 + MASK_ALIGN_BY_32);
2309 break;
2311 case OPT_mno_etrax100:
2312 target_flags
2313 &= ~(MASK_SVINTO
2314 + MASK_ETRAX4_ADD
2315 + MASK_ALIGN_BY_32);
2316 break;
2318 case OPT_m32_bit:
2319 case OPT_m32bit:
2320 target_flags
2321 |= (MASK_STACK_ALIGN
2322 + MASK_CONST_ALIGN
2323 + MASK_DATA_ALIGN
2324 + MASK_ALIGN_BY_32);
2325 break;
2327 case OPT_m16_bit:
2328 case OPT_m16bit:
2329 target_flags
2330 |= (MASK_STACK_ALIGN
2331 + MASK_CONST_ALIGN
2332 + MASK_DATA_ALIGN);
2333 break;
2335 case OPT_m8_bit:
2336 case OPT_m8bit:
2337 target_flags
2338 &= ~(MASK_STACK_ALIGN
2339 + MASK_CONST_ALIGN
2340 + MASK_DATA_ALIGN);
2341 break;
2343 default:
2344 break;
2347 CRIS_SUBTARGET_HANDLE_OPTION(code, arg, value);
2349 return true;
2352 /* The OVERRIDE_OPTIONS worker.
2353 As is the norm, this also parses -mfoo=bar type parameters. */
2355 void
2356 cris_override_options (void)
2358 if (cris_max_stackframe_str)
2360 cris_max_stackframe = atoi (cris_max_stackframe_str);
2362 /* Do some sanity checking. */
2363 if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2364 internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2365 cris_max_stackframe, 0x20000000);
2368 /* Let "-metrax4" and "-metrax100" change the cpu version. */
2369 if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2370 cris_cpu_version = CRIS_CPU_SVINTO;
2371 else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2372 cris_cpu_version = CRIS_CPU_ETRAX4;
2374 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2375 if (cris_cpu_str)
2377 cris_cpu_version
2378 = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2380 if (strcmp ("etrax4", cris_cpu_str) == 0)
2381 cris_cpu_version = 3;
2383 if (strcmp ("svinto", cris_cpu_str) == 0
2384 || strcmp ("etrax100", cris_cpu_str) == 0)
2385 cris_cpu_version = 8;
2387 if (strcmp ("ng", cris_cpu_str) == 0
2388 || strcmp ("etrax100lx", cris_cpu_str) == 0)
2389 cris_cpu_version = 10;
2391 if (cris_cpu_version < 0 || cris_cpu_version > 32)
2392 error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2393 cris_cpu_str);
2395 /* Set the target flags. */
2396 if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2397 target_flags |= MASK_ETRAX4_ADD;
2399 /* If this is Svinto or higher, align for 32 bit accesses. */
2400 if (cris_cpu_version >= CRIS_CPU_SVINTO)
2401 target_flags
2402 |= (MASK_SVINTO | MASK_ALIGN_BY_32
2403 | MASK_STACK_ALIGN | MASK_CONST_ALIGN
2404 | MASK_DATA_ALIGN);
2406 /* Note that we do not add new flags when it can be completely
2407 described with a macro that uses -mcpu=X. So
2408 TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */
2411 if (cris_tune_str)
2413 int cris_tune
2414 = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2416 if (strcmp ("etrax4", cris_tune_str) == 0)
2417 cris_tune = 3;
2419 if (strcmp ("svinto", cris_tune_str) == 0
2420 || strcmp ("etrax100", cris_tune_str) == 0)
2421 cris_tune = 8;
2423 if (strcmp ("ng", cris_tune_str) == 0
2424 || strcmp ("etrax100lx", cris_tune_str) == 0)
2425 cris_tune = 10;
2427 if (cris_tune < 0 || cris_tune > 32)
2428 error ("unknown CRIS cpu version specification in -mtune= : %s",
2429 cris_tune_str);
2431 if (cris_tune >= CRIS_CPU_SVINTO)
2432 /* We have currently nothing more to tune than alignment for
2433 memory accesses. */
2434 target_flags
2435 |= (MASK_STACK_ALIGN | MASK_CONST_ALIGN
2436 | MASK_DATA_ALIGN | MASK_ALIGN_BY_32);
2439 if (cris_cpu_version >= CRIS_CPU_V32)
2440 target_flags &= ~(MASK_SIDE_EFFECT_PREFIXES|MASK_MUL_BUG);
2442 if (flag_pic)
2444 /* Use error rather than warning, so invalid use is easily
2445 detectable. Still change to the values we expect, to avoid
2446 further errors. */
2447 if (! TARGET_LINUX)
2449 error ("-fPIC and -fpic are not supported in this configuration");
2450 flag_pic = 0;
2453 /* Turn off function CSE. We need to have the addresses reach the
2454 call expanders to get PLT-marked, as they could otherwise be
2455 compared against zero directly or indirectly. After visiting the
2456 call expanders they will then be cse:ed, as the call expanders
2457 force_reg the addresses, effectively forcing flag_no_function_cse
2458 to 0. */
2459 flag_no_function_cse = 1;
2462 if (write_symbols == DWARF2_DEBUG && ! TARGET_ELF)
2464 warning (0, "that particular -g option is invalid with -maout and -melinux");
2465 write_symbols = DBX_DEBUG;
2468 /* Set the per-function-data initializer. */
2469 init_machine_status = cris_init_machine_status;
2472 /* The TARGET_ASM_OUTPUT_MI_THUNK worker. */
2474 static void
2475 cris_asm_output_mi_thunk (FILE *stream,
2476 tree thunkdecl ATTRIBUTE_UNUSED,
2477 HOST_WIDE_INT delta,
2478 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
2479 tree funcdecl)
2481 if (delta > 0)
2482 fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2483 ADDITIVE_SIZE_MODIFIER (delta), delta,
2484 reg_names[CRIS_FIRST_ARG_REG]);
2485 else if (delta < 0)
2486 fprintf (stream, "\tsub%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2487 ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2488 reg_names[CRIS_FIRST_ARG_REG]);
2490 if (flag_pic)
2492 const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2494 name = (* targetm.strip_name_encoding) (name);
2496 if (TARGET_V32)
2498 fprintf (stream, "\tba ");
2499 assemble_name (stream, name);
2500 fprintf (stream, "%s\n", CRIS_PLT_PCOFFSET_SUFFIX);
2502 else
2504 fprintf (stream, "add.d ");
2505 assemble_name (stream, name);
2506 fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2509 else
2511 fprintf (stream, "jump ");
2512 assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2513 fprintf (stream, "\n");
2515 if (TARGET_V32)
2516 fprintf (stream, "\tnop\n");
2520 /* Boilerplate emitted at start of file.
2522 NO_APP *only at file start* means faster assembly. It also means
2523 comments are not allowed. In some cases comments will be output
2524 for debugging purposes. Make sure they are allowed then.
2526 We want a .file directive only if TARGET_ELF. */
2527 static void
2528 cris_file_start (void)
2530 /* These expressions can vary at run time, so we cannot put
2531 them into TARGET_INITIALIZER. */
2532 targetm.file_start_app_off = !(TARGET_PDEBUG || flag_print_asm_name);
2533 targetm.file_start_file_directive = TARGET_ELF;
2535 default_file_start ();
2538 /* Rename the function calls for integer multiply and divide. */
2539 static void
2540 cris_init_libfuncs (void)
2542 set_optab_libfunc (smul_optab, SImode, "__Mul");
2543 set_optab_libfunc (sdiv_optab, SImode, "__Div");
2544 set_optab_libfunc (udiv_optab, SImode, "__Udiv");
2545 set_optab_libfunc (smod_optab, SImode, "__Mod");
2546 set_optab_libfunc (umod_optab, SImode, "__Umod");
2549 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2550 mark functions. */
2552 void
2553 cris_init_expanders (void)
2555 /* Nothing here at the moment. */
2558 /* Zero initialization is OK for all current fields. */
2560 static struct machine_function *
2561 cris_init_machine_status (void)
2563 return GGC_CNEW (struct machine_function);
2566 /* Split a 2 word move (DI or presumably DF) into component parts.
2567 Originally a copy of gen_split_move_double in m32r.c. */
2570 cris_split_movdx (rtx *operands)
2572 enum machine_mode mode = GET_MODE (operands[0]);
2573 rtx dest = operands[0];
2574 rtx src = operands[1];
2575 rtx val;
2577 /* We used to have to handle (SUBREG (MEM)) here, but that should no
2578 longer happen; after reload there are no SUBREGs any more, and we're
2579 only called after reload. */
2580 CRIS_ASSERT (GET_CODE (dest) != SUBREG && GET_CODE (src) != SUBREG);
2582 start_sequence ();
2583 if (REG_P (dest))
2585 int dregno = REGNO (dest);
2587 /* Reg-to-reg copy. */
2588 if (REG_P (src))
2590 int sregno = REGNO (src);
2592 int reverse = (dregno == sregno + 1);
2594 /* We normally copy the low-numbered register first. However, if
2595 the first register operand 0 is the same as the second register of
2596 operand 1, we must copy in the opposite order. */
2597 emit_insn (gen_rtx_SET (VOIDmode,
2598 operand_subword (dest, reverse, TRUE, mode),
2599 operand_subword (src, reverse, TRUE, mode)));
2601 emit_insn (gen_rtx_SET (VOIDmode,
2602 operand_subword (dest, !reverse, TRUE, mode),
2603 operand_subword (src, !reverse, TRUE, mode)));
2605 /* Constant-to-reg copy. */
2606 else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE)
2608 rtx words[2];
2609 split_double (src, &words[0], &words[1]);
2610 emit_insn (gen_rtx_SET (VOIDmode,
2611 operand_subword (dest, 0, TRUE, mode),
2612 words[0]));
2614 emit_insn (gen_rtx_SET (VOIDmode,
2615 operand_subword (dest, 1, TRUE, mode),
2616 words[1]));
2618 /* Mem-to-reg copy. */
2619 else if (MEM_P (src))
2621 /* If the high-address word is used in the address, we must load it
2622 last. Otherwise, load it first. */
2623 rtx addr = XEXP (src, 0);
2624 int reverse
2625 = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2627 /* The original code implies that we can't do
2628 move.x [rN+],rM move.x [rN],rM+1
2629 when rN is dead, because of REG_NOTES damage. That is
2630 consistent with what I've seen, so don't try it.
2632 We have two different cases here; if the addr is POST_INC,
2633 just pass it through, otherwise add constants. */
2635 if (GET_CODE (addr) == POST_INC)
2637 rtx mem;
2638 rtx insn;
2640 /* Whenever we emit insns with post-incremented
2641 addresses ourselves, we must add a post-inc note
2642 manually. */
2643 mem = change_address (src, SImode, addr);
2644 insn
2645 = gen_rtx_SET (VOIDmode,
2646 operand_subword (dest, 0, TRUE, mode), mem);
2647 insn = emit_insn (insn);
2648 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2649 REG_NOTES (insn)
2650 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2651 REG_NOTES (insn));
2653 mem = copy_rtx (mem);
2654 insn
2655 = gen_rtx_SET (VOIDmode,
2656 operand_subword (dest, 1, TRUE, mode), mem);
2657 insn = emit_insn (insn);
2658 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2659 REG_NOTES (insn)
2660 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2661 REG_NOTES (insn));
2663 else
2665 /* Make sure we don't get any other addresses with
2666 embedded postincrements. They should be stopped in
2667 GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2668 safety. */
2669 if (side_effects_p (addr))
2670 fatal_insn ("unexpected side-effects in address", addr);
2672 emit_insn (gen_rtx_SET
2673 (VOIDmode,
2674 operand_subword (dest, reverse, TRUE, mode),
2675 change_address
2676 (src, SImode,
2677 plus_constant (addr,
2678 reverse * UNITS_PER_WORD))));
2679 emit_insn (gen_rtx_SET
2680 (VOIDmode,
2681 operand_subword (dest, ! reverse, TRUE, mode),
2682 change_address
2683 (src, SImode,
2684 plus_constant (addr,
2685 (! reverse) *
2686 UNITS_PER_WORD))));
2689 else
2690 internal_error ("Unknown src");
2692 /* Reg-to-mem copy or clear mem. */
2693 else if (MEM_P (dest)
2694 && (REG_P (src)
2695 || src == const0_rtx
2696 || src == CONST0_RTX (DFmode)))
2698 rtx addr = XEXP (dest, 0);
2700 if (GET_CODE (addr) == POST_INC)
2702 rtx mem;
2703 rtx insn;
2705 /* Whenever we emit insns with post-incremented addresses
2706 ourselves, we must add a post-inc note manually. */
2707 mem = change_address (dest, SImode, addr);
2708 insn
2709 = gen_rtx_SET (VOIDmode,
2710 mem, operand_subword (src, 0, TRUE, mode));
2711 insn = emit_insn (insn);
2712 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2713 REG_NOTES (insn)
2714 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2715 REG_NOTES (insn));
2717 mem = copy_rtx (mem);
2718 insn
2719 = gen_rtx_SET (VOIDmode,
2720 mem,
2721 operand_subword (src, 1, TRUE, mode));
2722 insn = emit_insn (insn);
2723 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2724 REG_NOTES (insn)
2725 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2726 REG_NOTES (insn));
2728 else
2730 /* Make sure we don't get any other addresses with embedded
2731 postincrements. They should be stopped in
2732 GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */
2733 if (side_effects_p (addr))
2734 fatal_insn ("unexpected side-effects in address", addr);
2736 emit_insn (gen_rtx_SET
2737 (VOIDmode,
2738 change_address (dest, SImode, addr),
2739 operand_subword (src, 0, TRUE, mode)));
2741 emit_insn (gen_rtx_SET
2742 (VOIDmode,
2743 change_address (dest, SImode,
2744 plus_constant (addr,
2745 UNITS_PER_WORD)),
2746 operand_subword (src, 1, TRUE, mode)));
2750 else
2751 internal_error ("Unknown dest");
2753 val = get_insns ();
2754 end_sequence ();
2755 return val;
2758 /* The expander for the prologue pattern name. */
2760 void
2761 cris_expand_prologue (void)
2763 int regno;
2764 int size = get_frame_size ();
2765 /* Shorten the used name for readability. */
2766 int cfoa_size = crtl->outgoing_args_size;
2767 int last_movem_reg = -1;
2768 int framesize = 0;
2769 rtx mem, insn;
2770 int return_address_on_stack = cris_return_address_on_stack ();
2771 int got_really_used = false;
2772 int n_movem_regs = 0;
2773 int pretend = crtl->args.pretend_args_size;
2775 /* Don't do anything if no prologues or epilogues are wanted. */
2776 if (!TARGET_PROLOGUE_EPILOGUE)
2777 return;
2779 CRIS_ASSERT (size >= 0);
2781 if (crtl->uses_pic_offset_table)
2783 /* A reference may have been optimized out (like the abort () in
2784 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
2785 it's still used. */
2786 push_topmost_sequence ();
2787 got_really_used
2788 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
2789 pop_topmost_sequence ();
2792 /* Align the size to what's best for the CPU model. */
2793 if (TARGET_STACK_ALIGN)
2794 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
2796 if (pretend)
2798 /* See also cris_setup_incoming_varargs where
2799 cfun->machine->stdarg_regs is set. There are other setters of
2800 crtl->args.pretend_args_size than stdarg handling, like
2801 for an argument passed with parts in R13 and stack. We must
2802 not store R13 into the pretend-area for that case, as GCC does
2803 that itself. "Our" store would be marked as redundant and GCC
2804 will attempt to remove it, which will then be flagged as an
2805 internal error; trying to remove a frame-related insn. */
2806 int stdarg_regs = cfun->machine->stdarg_regs;
2808 framesize += pretend;
2810 for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
2811 stdarg_regs > 0;
2812 regno--, pretend -= 4, stdarg_regs--)
2814 insn = emit_insn (gen_rtx_SET (VOIDmode,
2815 stack_pointer_rtx,
2816 plus_constant (stack_pointer_rtx,
2817 -4)));
2818 /* FIXME: When dwarf2 frame output and unless asynchronous
2819 exceptions, make dwarf2 bundle together all stack
2820 adjustments like it does for registers between stack
2821 adjustments. */
2822 RTX_FRAME_RELATED_P (insn) = 1;
2824 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2825 set_mem_alias_set (mem, get_varargs_alias_set ());
2826 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2828 /* Note the absence of RTX_FRAME_RELATED_P on the above insn:
2829 the value isn't restored, so we don't want to tell dwarf2
2830 that it's been stored to stack, else EH handling info would
2831 get confused. */
2834 /* For other setters of crtl->args.pretend_args_size, we
2835 just adjust the stack by leaving the remaining size in
2836 "pretend", handled below. */
2839 /* Save SRP if not a leaf function. */
2840 if (return_address_on_stack)
2842 insn = emit_insn (gen_rtx_SET (VOIDmode,
2843 stack_pointer_rtx,
2844 plus_constant (stack_pointer_rtx,
2845 -4 - pretend)));
2846 pretend = 0;
2847 RTX_FRAME_RELATED_P (insn) = 1;
2849 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2850 set_mem_alias_set (mem, get_frame_alias_set ());
2851 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM));
2852 RTX_FRAME_RELATED_P (insn) = 1;
2853 framesize += 4;
2856 /* Set up the frame pointer, if needed. */
2857 if (frame_pointer_needed)
2859 insn = emit_insn (gen_rtx_SET (VOIDmode,
2860 stack_pointer_rtx,
2861 plus_constant (stack_pointer_rtx,
2862 -4 - pretend)));
2863 pretend = 0;
2864 RTX_FRAME_RELATED_P (insn) = 1;
2866 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2867 set_mem_alias_set (mem, get_frame_alias_set ());
2868 insn = emit_move_insn (mem, frame_pointer_rtx);
2869 RTX_FRAME_RELATED_P (insn) = 1;
2871 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
2872 RTX_FRAME_RELATED_P (insn) = 1;
2874 framesize += 4;
2877 /* Between frame-pointer and saved registers lie the area for local
2878 variables. If we get here with "pretended" size remaining, count
2879 it into the general stack size. */
2880 size += pretend;
2882 /* Get a contiguous sequence of registers, starting with R0, that need
2883 to be saved. */
2884 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
2886 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
2888 n_movem_regs++;
2890 /* Check if movem may be used for registers so far. */
2891 if (regno == last_movem_reg + 1)
2892 /* Yes, update next expected register. */
2893 last_movem_reg = regno;
2894 else
2896 /* We cannot use movem for all registers. We have to flush
2897 any movem:ed registers we got so far. */
2898 if (last_movem_reg != -1)
2900 int n_saved
2901 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2903 /* It is a win to use a side-effect assignment for
2904 64 <= size <= 128. But side-effect on movem was
2905 not usable for CRIS v0..3. Also only do it if
2906 side-effects insns are allowed. */
2907 if ((last_movem_reg + 1) * 4 + size >= 64
2908 && (last_movem_reg + 1) * 4 + size <= 128
2909 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2910 && TARGET_SIDE_EFFECT_PREFIXES)
2913 = gen_rtx_MEM (SImode,
2914 plus_constant (stack_pointer_rtx,
2915 -(n_saved * 4 + size)));
2916 set_mem_alias_set (mem, get_frame_alias_set ());
2917 insn
2918 = cris_emit_movem_store (mem, GEN_INT (n_saved),
2919 -(n_saved * 4 + size),
2920 true);
2922 else
2924 insn
2925 = gen_rtx_SET (VOIDmode,
2926 stack_pointer_rtx,
2927 plus_constant (stack_pointer_rtx,
2928 -(n_saved * 4 + size)));
2929 insn = emit_insn (insn);
2930 RTX_FRAME_RELATED_P (insn) = 1;
2932 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2933 set_mem_alias_set (mem, get_frame_alias_set ());
2934 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2935 0, true);
2938 framesize += n_saved * 4 + size;
2939 last_movem_reg = -1;
2940 size = 0;
2943 insn = emit_insn (gen_rtx_SET (VOIDmode,
2944 stack_pointer_rtx,
2945 plus_constant (stack_pointer_rtx,
2946 -4 - size)));
2947 RTX_FRAME_RELATED_P (insn) = 1;
2949 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2950 set_mem_alias_set (mem, get_frame_alias_set ());
2951 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2952 RTX_FRAME_RELATED_P (insn) = 1;
2954 framesize += 4 + size;
2955 size = 0;
2960 /* Check after, if we could movem all registers. This is the normal case. */
2961 if (last_movem_reg != -1)
2963 int n_saved
2964 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2966 /* Side-effect on movem was not usable for CRIS v0..3. Also only
2967 do it if side-effects insns are allowed. */
2968 if ((last_movem_reg + 1) * 4 + size >= 64
2969 && (last_movem_reg + 1) * 4 + size <= 128
2970 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2971 && TARGET_SIDE_EFFECT_PREFIXES)
2974 = gen_rtx_MEM (SImode,
2975 plus_constant (stack_pointer_rtx,
2976 -(n_saved * 4 + size)));
2977 set_mem_alias_set (mem, get_frame_alias_set ());
2978 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2979 -(n_saved * 4 + size), true);
2981 else
2983 insn
2984 = gen_rtx_SET (VOIDmode,
2985 stack_pointer_rtx,
2986 plus_constant (stack_pointer_rtx,
2987 -(n_saved * 4 + size)));
2988 insn = emit_insn (insn);
2989 RTX_FRAME_RELATED_P (insn) = 1;
2991 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2992 set_mem_alias_set (mem, get_frame_alias_set ());
2993 insn = cris_emit_movem_store (mem, GEN_INT (n_saved), 0, true);
2996 framesize += n_saved * 4 + size;
2997 /* We have to put outgoing argument space after regs. */
2998 if (cfoa_size)
3000 insn = emit_insn (gen_rtx_SET (VOIDmode,
3001 stack_pointer_rtx,
3002 plus_constant (stack_pointer_rtx,
3003 -cfoa_size)));
3004 RTX_FRAME_RELATED_P (insn) = 1;
3005 framesize += cfoa_size;
3008 else if ((size + cfoa_size) > 0)
3010 insn = emit_insn (gen_rtx_SET (VOIDmode,
3011 stack_pointer_rtx,
3012 plus_constant (stack_pointer_rtx,
3013 -(cfoa_size + size))));
3014 RTX_FRAME_RELATED_P (insn) = 1;
3015 framesize += size + cfoa_size;
3018 /* Set up the PIC register, if it is used. */
3019 if (got_really_used)
3021 rtx got
3022 = gen_rtx_UNSPEC (SImode, gen_rtvec (1, const0_rtx), CRIS_UNSPEC_GOT);
3023 emit_move_insn (pic_offset_table_rtx, got);
3025 /* FIXME: This is a cover-up for flow2 messing up; it doesn't
3026 follow exceptional paths and tries to delete the GOT load as
3027 unused, if it isn't used on the non-exceptional paths. Other
3028 ports have similar or other cover-ups, or plain bugs marking
3029 the GOT register load as maybe-dead. To see this, remove the
3030 line below and try libsupc++/vec.cc or a trivial
3031 "static void y (); void x () {try {y ();} catch (...) {}}". */
3032 emit_use (pic_offset_table_rtx);
3035 if (cris_max_stackframe && framesize > cris_max_stackframe)
3036 warning (0, "stackframe too big: %d bytes", framesize);
3039 /* The expander for the epilogue pattern. */
3041 void
3042 cris_expand_epilogue (void)
3044 int regno;
3045 int size = get_frame_size ();
3046 int last_movem_reg = -1;
3047 int argspace_offset = crtl->outgoing_args_size;
3048 int pretend = crtl->args.pretend_args_size;
3049 rtx mem;
3050 bool return_address_on_stack = cris_return_address_on_stack ();
3051 /* A reference may have been optimized out
3052 (like the abort () in fde_split in unwind-dw2-fde.c, at least 3.2.1)
3053 so check that it's still used. */
3054 int got_really_used = false;
3055 int n_movem_regs = 0;
3057 if (!TARGET_PROLOGUE_EPILOGUE)
3058 return;
3060 if (crtl->uses_pic_offset_table)
3062 /* A reference may have been optimized out (like the abort () in
3063 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
3064 it's still used. */
3065 push_topmost_sequence ();
3066 got_really_used
3067 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
3068 pop_topmost_sequence ();
3071 /* Align byte count of stack frame. */
3072 if (TARGET_STACK_ALIGN)
3073 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
3075 /* Check how many saved regs we can movem. They start at r0 and must
3076 be contiguous. */
3077 for (regno = 0;
3078 regno < FIRST_PSEUDO_REGISTER;
3079 regno++)
3080 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3082 n_movem_regs++;
3084 if (regno == last_movem_reg + 1)
3085 last_movem_reg = regno;
3086 else
3087 break;
3090 /* If there was only one register that really needed to be saved
3091 through movem, don't use movem. */
3092 if (n_movem_regs == 1)
3093 last_movem_reg = -1;
3095 /* Now emit "normal" move insns for all regs higher than the movem
3096 regs. */
3097 for (regno = FIRST_PSEUDO_REGISTER - 1;
3098 regno > last_movem_reg;
3099 regno--)
3100 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3102 rtx insn;
3104 if (argspace_offset)
3106 /* There is an area for outgoing parameters located before
3107 the saved registers. We have to adjust for that. */
3108 emit_insn (gen_rtx_SET (VOIDmode,
3109 stack_pointer_rtx,
3110 plus_constant (stack_pointer_rtx,
3111 argspace_offset)));
3112 /* Make sure we only do this once. */
3113 argspace_offset = 0;
3116 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3117 stack_pointer_rtx));
3118 set_mem_alias_set (mem, get_frame_alias_set ());
3119 insn = emit_move_insn (gen_rtx_raw_REG (SImode, regno), mem);
3121 /* Whenever we emit insns with post-incremented addresses
3122 ourselves, we must add a post-inc note manually. */
3123 REG_NOTES (insn)
3124 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3127 /* If we have any movem-restore, do it now. */
3128 if (last_movem_reg != -1)
3130 rtx insn;
3132 if (argspace_offset)
3134 emit_insn (gen_rtx_SET (VOIDmode,
3135 stack_pointer_rtx,
3136 plus_constant (stack_pointer_rtx,
3137 argspace_offset)));
3138 argspace_offset = 0;
3141 mem = gen_rtx_MEM (SImode,
3142 gen_rtx_POST_INC (SImode, stack_pointer_rtx));
3143 set_mem_alias_set (mem, get_frame_alias_set ());
3144 insn
3145 = emit_insn (cris_gen_movem_load (mem,
3146 GEN_INT (last_movem_reg + 1), 0));
3147 /* Whenever we emit insns with post-incremented addresses
3148 ourselves, we must add a post-inc note manually. */
3149 if (side_effects_p (PATTERN (insn)))
3150 REG_NOTES (insn)
3151 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3154 /* If we don't clobber all of the allocated stack area (we've already
3155 deallocated saved registers), GCC might want to schedule loads from
3156 the stack to *after* the stack-pointer restore, which introduces an
3157 interrupt race condition. This happened for the initial-value
3158 SRP-restore for g++.dg/eh/registers1.C (noticed by inspection of
3159 other failure for that test). It also happened for the stack slot
3160 for the return value in (one version of)
3161 linux/fs/dcache.c:__d_lookup, at least with "-O2
3162 -fno-omit-frame-pointer". */
3164 /* Restore frame pointer if necessary. */
3165 if (frame_pointer_needed)
3167 rtx insn;
3169 emit_insn (gen_cris_frame_deallocated_barrier ());
3171 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
3172 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3173 stack_pointer_rtx));
3174 set_mem_alias_set (mem, get_frame_alias_set ());
3175 insn = emit_move_insn (frame_pointer_rtx, mem);
3177 /* Whenever we emit insns with post-incremented addresses
3178 ourselves, we must add a post-inc note manually. */
3179 REG_NOTES (insn)
3180 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3182 else if ((size + argspace_offset) != 0)
3184 emit_insn (gen_cris_frame_deallocated_barrier ());
3186 /* If there was no frame-pointer to restore sp from, we must
3187 explicitly deallocate local variables. */
3189 /* Handle space for outgoing parameters that hasn't been handled
3190 yet. */
3191 size += argspace_offset;
3193 emit_insn (gen_rtx_SET (VOIDmode,
3194 stack_pointer_rtx,
3195 plus_constant (stack_pointer_rtx, size)));
3198 /* If this function has no pushed register parameters
3199 (stdargs/varargs), and if it is not a leaf function, then we have
3200 the return address on the stack. */
3201 if (return_address_on_stack && pretend == 0)
3203 if (TARGET_V32 || crtl->calls_eh_return)
3205 rtx mem;
3206 rtx insn;
3207 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3208 mem = gen_rtx_MEM (SImode,
3209 gen_rtx_POST_INC (SImode,
3210 stack_pointer_rtx));
3211 set_mem_alias_set (mem, get_frame_alias_set ());
3212 insn = emit_move_insn (srpreg, mem);
3214 /* Whenever we emit insns with post-incremented addresses
3215 ourselves, we must add a post-inc note manually. */
3216 REG_NOTES (insn)
3217 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3219 if (crtl->calls_eh_return)
3220 emit_insn (gen_addsi3 (stack_pointer_rtx,
3221 stack_pointer_rtx,
3222 gen_rtx_raw_REG (SImode,
3223 CRIS_STACKADJ_REG)));
3224 cris_expand_return (false);
3226 else
3227 cris_expand_return (true);
3229 return;
3232 /* If we pushed some register parameters, then adjust the stack for
3233 them. */
3234 if (pretend != 0)
3236 /* If SRP is stored on the way, we need to restore it first. */
3237 if (return_address_on_stack)
3239 rtx mem;
3240 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3241 rtx insn;
3243 mem = gen_rtx_MEM (SImode,
3244 gen_rtx_POST_INC (SImode,
3245 stack_pointer_rtx));
3246 set_mem_alias_set (mem, get_frame_alias_set ());
3247 insn = emit_move_insn (srpreg, mem);
3249 /* Whenever we emit insns with post-incremented addresses
3250 ourselves, we must add a post-inc note manually. */
3251 REG_NOTES (insn)
3252 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3255 emit_insn (gen_rtx_SET (VOIDmode,
3256 stack_pointer_rtx,
3257 plus_constant (stack_pointer_rtx, pretend)));
3260 /* Perform the "physical" unwinding that the EH machinery calculated. */
3261 if (crtl->calls_eh_return)
3262 emit_insn (gen_addsi3 (stack_pointer_rtx,
3263 stack_pointer_rtx,
3264 gen_rtx_raw_REG (SImode,
3265 CRIS_STACKADJ_REG)));
3266 cris_expand_return (false);
3269 /* Worker function for generating movem from mem for load_multiple. */
3272 cris_gen_movem_load (rtx src, rtx nregs_rtx, int nprefix)
3274 int nregs = INTVAL (nregs_rtx);
3275 rtvec vec;
3276 int eltno = 1;
3277 int i;
3278 rtx srcreg = XEXP (src, 0);
3279 unsigned int regno = nregs - 1;
3280 int regno_inc = -1;
3282 if (TARGET_V32)
3284 regno = 0;
3285 regno_inc = 1;
3288 if (GET_CODE (srcreg) == POST_INC)
3289 srcreg = XEXP (srcreg, 0);
3291 CRIS_ASSERT (REG_P (srcreg));
3293 /* Don't use movem for just one insn. The insns are equivalent except
3294 for the pipeline hazard (on v32); movem does not forward the loaded
3295 registers so there's a three cycles penalty for their use. */
3296 if (nregs == 1)
3297 return gen_movsi (gen_rtx_REG (SImode, 0), src);
3299 vec = rtvec_alloc (nprefix + nregs
3300 + (GET_CODE (XEXP (src, 0)) == POST_INC));
3302 if (GET_CODE (XEXP (src, 0)) == POST_INC)
3304 RTVEC_ELT (vec, nprefix + 1)
3305 = gen_rtx_SET (VOIDmode, srcreg, plus_constant (srcreg, nregs * 4));
3306 eltno++;
3309 src = replace_equiv_address (src, srcreg);
3310 RTVEC_ELT (vec, nprefix)
3311 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno), src);
3312 regno += regno_inc;
3314 for (i = 1; i < nregs; i++, eltno++)
3316 RTVEC_ELT (vec, nprefix + eltno)
3317 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno),
3318 adjust_address_nv (src, SImode, i * 4));
3319 regno += regno_inc;
3322 return gen_rtx_PARALLEL (VOIDmode, vec);
3325 /* Worker function for generating movem to mem. If FRAME_RELATED, notes
3326 are added that the dwarf2 machinery understands. */
3329 cris_emit_movem_store (rtx dest, rtx nregs_rtx, int increment,
3330 bool frame_related)
3332 int nregs = INTVAL (nregs_rtx);
3333 rtvec vec;
3334 int eltno = 1;
3335 int i;
3336 rtx insn;
3337 rtx destreg = XEXP (dest, 0);
3338 unsigned int regno = nregs - 1;
3339 int regno_inc = -1;
3341 if (TARGET_V32)
3343 regno = 0;
3344 regno_inc = 1;
3347 if (GET_CODE (destreg) == POST_INC)
3348 increment += nregs * 4;
3350 if (GET_CODE (destreg) == POST_INC || GET_CODE (destreg) == PLUS)
3351 destreg = XEXP (destreg, 0);
3353 CRIS_ASSERT (REG_P (destreg));
3355 /* Don't use movem for just one insn. The insns are equivalent except
3356 for the pipeline hazard (on v32); movem does not forward the loaded
3357 registers so there's a three cycles penalty for use. */
3358 if (nregs == 1)
3360 rtx mov = gen_rtx_SET (VOIDmode, dest, gen_rtx_REG (SImode, 0));
3362 if (increment == 0)
3364 insn = emit_insn (mov);
3365 if (frame_related)
3366 RTX_FRAME_RELATED_P (insn) = 1;
3367 return insn;
3370 /* If there was a request for a side-effect, create the ordinary
3371 parallel. */
3372 vec = rtvec_alloc (2);
3374 RTVEC_ELT (vec, 0) = mov;
3375 RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, destreg,
3376 plus_constant (destreg, increment));
3377 if (frame_related)
3379 RTX_FRAME_RELATED_P (mov) = 1;
3380 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3383 else
3385 vec = rtvec_alloc (nregs + (increment != 0 ? 1 : 0));
3386 RTVEC_ELT (vec, 0)
3387 = gen_rtx_SET (VOIDmode,
3388 replace_equiv_address (dest,
3389 plus_constant (destreg,
3390 increment)),
3391 gen_rtx_REG (SImode, regno));
3392 regno += regno_inc;
3394 /* The dwarf2 info wants this mark on each component in a parallel
3395 that's part of the prologue (though it's optional on the first
3396 component). */
3397 if (frame_related)
3398 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 0)) = 1;
3400 if (increment != 0)
3402 RTVEC_ELT (vec, 1)
3403 = gen_rtx_SET (VOIDmode, destreg,
3404 plus_constant (destreg,
3405 increment != 0
3406 ? increment : nregs * 4));
3407 eltno++;
3409 if (frame_related)
3410 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3412 /* Don't call adjust_address_nv on a post-incremented address if
3413 we can help it. */
3414 if (GET_CODE (XEXP (dest, 0)) == POST_INC)
3415 dest = replace_equiv_address (dest, destreg);
3418 for (i = 1; i < nregs; i++, eltno++)
3420 RTVEC_ELT (vec, eltno)
3421 = gen_rtx_SET (VOIDmode, adjust_address_nv (dest, SImode, i * 4),
3422 gen_rtx_REG (SImode, regno));
3423 if (frame_related)
3424 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, eltno)) = 1;
3425 regno += regno_inc;
3429 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, vec));
3431 /* Because dwarf2out.c handles the insns in a parallel as a sequence,
3432 we need to keep the stack adjustment separate, after the
3433 MEM-setters. Else the stack-adjustment in the second component of
3434 the parallel would be mishandled; the offsets for the SETs that
3435 follow it would be wrong. We prepare for this by adding a
3436 REG_FRAME_RELATED_EXPR with the MEM-setting parts in a SEQUENCE
3437 followed by the increment. Note that we have FRAME_RELATED_P on
3438 all the SETs, including the original stack adjustment SET in the
3439 parallel. */
3440 if (frame_related)
3442 if (increment != 0)
3444 rtx seq = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nregs + 1));
3445 XVECEXP (seq, 0, 0) = copy_rtx (XVECEXP (PATTERN (insn), 0, 0));
3446 for (i = 1; i < nregs; i++)
3447 XVECEXP (seq, 0, i)
3448 = copy_rtx (XVECEXP (PATTERN (insn), 0, i + 1));
3449 XVECEXP (seq, 0, nregs) = copy_rtx (XVECEXP (PATTERN (insn), 0, 1));
3450 REG_NOTES (insn)
3451 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, seq,
3452 REG_NOTES (insn));
3455 RTX_FRAME_RELATED_P (insn) = 1;
3458 return insn;
3461 /* Worker function for expanding the address for PIC function calls. */
3463 void
3464 cris_expand_pic_call_address (rtx *opp)
3466 rtx op = *opp;
3468 gcc_assert (MEM_P (op));
3469 op = XEXP (op, 0);
3471 /* It might be that code can be generated that jumps to 0 (or to a
3472 specific address). Don't die on that. (There is a
3473 testcase.) */
3474 if (CONSTANT_ADDRESS_P (op) && !CONST_INT_P (op))
3476 enum cris_pic_symbol_type t = cris_pic_symbol_type_of (op);
3478 CRIS_ASSERT (can_create_pseudo_p ());
3480 /* For local symbols (non-PLT), just get the plain symbol
3481 reference into a register. For symbols that can be PLT, make
3482 them PLT. */
3483 if (t == cris_rel_symbol)
3485 /* For v32, we're fine as-is; just PICify the symbol. Forcing
3486 into a register caused performance regression for 3.2.1,
3487 observable in __floatdidf and elsewhere in libgcc. */
3488 if (TARGET_V32)
3490 rtx sym = GET_CODE (op) != CONST ? op : get_related_value (op);
3491 HOST_WIDE_INT offs = get_integer_term (op);
3493 /* We can't get calls to sym+N, N integer, can we? */
3494 gcc_assert (offs == 0);
3496 op = gen_rtx_CONST (Pmode,
3497 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, sym),
3498 CRIS_UNSPEC_PCREL));
3500 else
3501 op = force_reg (Pmode, op);
3503 else if (t == cris_got_symbol)
3505 if (TARGET_AVOID_GOTPLT)
3507 /* Change a "jsr sym" into (allocate register rM, rO)
3508 "move.d (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_GOTREL)),rM"
3509 "add.d rPIC,rM,rO", "jsr rO" for pre-v32 and
3510 "jsr (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_PCREL))"
3511 for v32. */
3512 rtx tem, rm, ro;
3513 gcc_assert (can_create_pseudo_p ());
3514 crtl->uses_pic_offset_table = 1;
3515 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3516 TARGET_V32
3517 ? CRIS_UNSPEC_PLT_PCREL
3518 : CRIS_UNSPEC_PLT_GOTREL);
3519 tem = gen_rtx_CONST (Pmode, tem);
3520 if (TARGET_V32)
3521 op = tem;
3522 else
3524 rm = gen_reg_rtx (Pmode);
3525 emit_move_insn (rm, tem);
3526 ro = gen_reg_rtx (Pmode);
3527 if (expand_binop (Pmode, add_optab, rm,
3528 pic_offset_table_rtx,
3529 ro, 0, OPTAB_LIB_WIDEN) != ro)
3530 internal_error ("expand_binop failed in movsi got");
3531 op = ro;
3534 else
3536 /* Change a "jsr sym" into (allocate register rM, rO)
3537 "move.d (const (unspec [sym] CRIS_UNSPEC_PLTGOTREAD)),rM"
3538 "add.d rPIC,rM,rO" "jsr [rO]" with the memory access
3539 marked as not trapping and not aliasing. No "move.d
3540 [rO],rP" as that would invite to re-use of a value
3541 that should not be reused. FIXME: Need a peephole2
3542 for cases when this is cse:d from the call, to change
3543 back to just get the PLT entry address, so we don't
3544 resolve the same symbol over and over (the memory
3545 access of the PLTGOT isn't constant). */
3546 rtx tem, mem, rm, ro;
3548 gcc_assert (can_create_pseudo_p ());
3549 crtl->uses_pic_offset_table = 1;
3550 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3551 CRIS_UNSPEC_PLTGOTREAD);
3552 rm = gen_reg_rtx (Pmode);
3553 emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
3554 ro = gen_reg_rtx (Pmode);
3555 if (expand_binop (Pmode, add_optab, rm,
3556 pic_offset_table_rtx,
3557 ro, 0, OPTAB_LIB_WIDEN) != ro)
3558 internal_error ("expand_binop failed in movsi got");
3559 mem = gen_rtx_MEM (Pmode, ro);
3561 /* This MEM doesn't alias anything. Whether it aliases
3562 other same symbols is unimportant. */
3563 set_mem_alias_set (mem, new_alias_set ());
3564 MEM_NOTRAP_P (mem) = 1;
3565 op = mem;
3568 else
3569 /* Can't possibly get a GOT-needing-fixup for a function-call,
3570 right? */
3571 fatal_insn ("Unidentifiable call op", op);
3573 *opp = replace_equiv_address (*opp, op);
3577 /* Make sure operands are in the right order for an addsi3 insn as
3578 generated by a define_split. Nothing but REG_P as the first
3579 operand is recognized by addsi3 after reload. OPERANDS contains
3580 the operands, with the first at OPERANDS[N] and the second at
3581 OPERANDS[N+1]. */
3583 void
3584 cris_order_for_addsi3 (rtx *operands, int n)
3586 if (!REG_P (operands[n]))
3588 rtx tem = operands[n];
3589 operands[n] = operands[n + 1];
3590 operands[n + 1] = tem;
3594 /* Use from within code, from e.g. PRINT_OPERAND and
3595 PRINT_OPERAND_ADDRESS. Macros used in output_addr_const need to emit
3596 different things depending on whether code operand or constant is
3597 emitted. */
3599 static void
3600 cris_output_addr_const (FILE *file, rtx x)
3602 in_code++;
3603 output_addr_const (file, x);
3604 in_code--;
3607 /* Worker function for ASM_OUTPUT_SYMBOL_REF. */
3609 void
3610 cris_asm_output_symbol_ref (FILE *file, rtx x)
3612 gcc_assert (GET_CODE (x) == SYMBOL_REF);
3614 if (flag_pic && in_code > 0)
3616 const char *origstr = XSTR (x, 0);
3617 const char *str;
3618 str = (* targetm.strip_name_encoding) (origstr);
3619 assemble_name (file, str);
3621 /* Sanity check. */
3622 if (!TARGET_V32 && !crtl->uses_pic_offset_table)
3623 output_operand_lossage ("PIC register isn't set up");
3625 else
3626 assemble_name (file, XSTR (x, 0));
3629 /* Worker function for ASM_OUTPUT_LABEL_REF. */
3631 void
3632 cris_asm_output_label_ref (FILE *file, char *buf)
3634 if (flag_pic && in_code > 0)
3636 assemble_name (file, buf);
3638 /* Sanity check. */
3639 if (!TARGET_V32 && !crtl->uses_pic_offset_table)
3640 internal_error ("emitting PIC operand, but PIC register isn't set up");
3642 else
3643 assemble_name (file, buf);
3646 /* Worker function for OUTPUT_ADDR_CONST_EXTRA. */
3648 bool
3649 cris_output_addr_const_extra (FILE *file, rtx xconst)
3651 switch (GET_CODE (xconst))
3653 rtx x;
3655 case UNSPEC:
3656 x = XVECEXP (xconst, 0, 0);
3657 CRIS_ASSERT (GET_CODE (x) == SYMBOL_REF
3658 || GET_CODE (x) == LABEL_REF
3659 || GET_CODE (x) == CONST);
3660 output_addr_const (file, x);
3661 switch (XINT (xconst, 1))
3663 case CRIS_UNSPEC_PCREL:
3664 /* We only get this with -fpic/PIC to tell it apart from an
3665 invalid symbol. We can't tell here, but it should only
3666 be the operand of a call or movsi. */
3667 gcc_assert (TARGET_V32 && flag_pic);
3668 break;
3670 case CRIS_UNSPEC_PLT_PCREL:
3671 gcc_assert (TARGET_V32);
3672 fprintf (file, ":PLT");
3673 break;
3675 case CRIS_UNSPEC_PLT_GOTREL:
3676 gcc_assert (!TARGET_V32);
3677 fprintf (file, ":PLTG");
3678 break;
3680 case CRIS_UNSPEC_GOTREL:
3681 gcc_assert (!TARGET_V32);
3682 fprintf (file, ":GOTOFF");
3683 break;
3685 case CRIS_UNSPEC_GOTREAD:
3686 if (flag_pic == 1)
3687 fprintf (file, ":GOT16");
3688 else
3689 fprintf (file, ":GOT");
3690 break;
3692 case CRIS_UNSPEC_PLTGOTREAD:
3693 if (flag_pic == 1)
3694 fprintf (file, CRIS_GOTPLT_SUFFIX "16");
3695 else
3696 fprintf (file, CRIS_GOTPLT_SUFFIX);
3697 break;
3699 default:
3700 gcc_unreachable ();
3702 return true;
3704 default:
3705 return false;
3709 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3711 static rtx
3712 cris_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3713 int incoming ATTRIBUTE_UNUSED)
3715 return gen_rtx_REG (Pmode, CRIS_STRUCT_VALUE_REGNUM);
3718 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3720 static void
3721 cris_setup_incoming_varargs (CUMULATIVE_ARGS *ca,
3722 enum machine_mode mode ATTRIBUTE_UNUSED,
3723 tree type ATTRIBUTE_UNUSED,
3724 int *pretend_arg_size,
3725 int second_time)
3727 if (ca->regs < CRIS_MAX_ARGS_IN_REGS)
3729 int stdarg_regs = CRIS_MAX_ARGS_IN_REGS - ca->regs;
3730 cfun->machine->stdarg_regs = stdarg_regs;
3731 *pretend_arg_size = stdarg_regs * 4;
3734 if (TARGET_PDEBUG)
3735 fprintf (asm_out_file,
3736 "\n; VA:: ANSI: %d args before, anon @ #%d, %dtime\n",
3737 ca->regs, *pretend_arg_size, second_time);
3740 /* Return true if TYPE must be passed by invisible reference.
3741 For cris, we pass <= 8 bytes by value, others by reference. */
3743 static bool
3744 cris_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
3745 enum machine_mode mode, const_tree type,
3746 bool named ATTRIBUTE_UNUSED)
3748 return (targetm.calls.must_pass_in_stack (mode, type)
3749 || CRIS_FUNCTION_ARG_SIZE (mode, type) > 8);
3753 static int
3754 cris_arg_partial_bytes (CUMULATIVE_ARGS *ca, enum machine_mode mode,
3755 tree type, bool named ATTRIBUTE_UNUSED)
3757 if (ca->regs == CRIS_MAX_ARGS_IN_REGS - 1
3758 && !targetm.calls.must_pass_in_stack (mode, type)
3759 && CRIS_FUNCTION_ARG_SIZE (mode, type) > 4
3760 && CRIS_FUNCTION_ARG_SIZE (mode, type) <= 8)
3761 return UNITS_PER_WORD;
3762 else
3763 return 0;
3766 /* Worker function for TARGET_MD_ASM_CLOBBERS. */
3768 static tree
3769 cris_md_asm_clobbers (tree outputs, tree inputs, tree in_clobbers)
3771 HARD_REG_SET mof_set;
3772 tree clobbers;
3773 tree t;
3775 CLEAR_HARD_REG_SET (mof_set);
3776 SET_HARD_REG_BIT (mof_set, CRIS_MOF_REGNUM);
3778 /* For the time being, all asms clobber condition codes. Revisit when
3779 there's a reasonable use for inputs/outputs that mention condition
3780 codes. */
3781 clobbers
3782 = tree_cons (NULL_TREE,
3783 build_string (strlen (reg_names[CRIS_CC0_REGNUM]),
3784 reg_names[CRIS_CC0_REGNUM]),
3785 in_clobbers);
3787 for (t = outputs; t != NULL; t = TREE_CHAIN (t))
3789 tree val = TREE_VALUE (t);
3791 /* The constraint letter for the singleton register class of MOF
3792 is 'h'. If it's mentioned in the constraints, the asm is
3793 MOF-aware and adding it to the clobbers would cause it to have
3794 impossible constraints. */
3795 if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
3796 'h') != NULL
3797 || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
3798 return clobbers;
3801 for (t = inputs; t != NULL; t = TREE_CHAIN (t))
3803 tree val = TREE_VALUE (t);
3805 if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
3806 'h') != NULL
3807 || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
3808 return clobbers;
3811 return tree_cons (NULL_TREE,
3812 build_string (strlen (reg_names[CRIS_MOF_REGNUM]),
3813 reg_names[CRIS_MOF_REGNUM]),
3814 clobbers);
3817 #if 0
3818 /* Various small functions to replace macros. Only called from a
3819 debugger. They might collide with gcc functions or system functions,
3820 so only emit them when '#if 1' above. */
3822 enum rtx_code Get_code (rtx);
3824 enum rtx_code
3825 Get_code (rtx x)
3827 return GET_CODE (x);
3830 const char *Get_mode (rtx);
3832 const char *
3833 Get_mode (rtx x)
3835 return GET_MODE_NAME (GET_MODE (x));
3838 rtx Xexp (rtx, int);
3841 Xexp (rtx x, int n)
3843 return XEXP (x, n);
3846 rtx Xvecexp (rtx, int, int);
3849 Xvecexp (rtx x, int n, int m)
3851 return XVECEXP (x, n, m);
3854 int Get_rtx_len (rtx);
3857 Get_rtx_len (rtx x)
3859 return GET_RTX_LENGTH (GET_CODE (x));
3862 /* Use upper-case to distinguish from local variables that are sometimes
3863 called next_insn and prev_insn. */
3865 rtx Next_insn (rtx);
3868 Next_insn (rtx insn)
3870 return NEXT_INSN (insn);
3873 rtx Prev_insn (rtx);
3876 Prev_insn (rtx insn)
3878 return PREV_INSN (insn);
3880 #endif
3882 #include "gt-cris.h"
3885 * Local variables:
3886 * eval: (c-set-style "gnu")
3887 * indent-tabs-mode: t
3888 * End: