hashtab.h: Update GTY annotations to new syntax
[official-gcc.git] / gcc / config / cris / cris.c
blob2112670de6c75af5fb7bd0166d1edcacea882c54
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;
1434 cc_status.value1 = SET_SRC (exp);
1436 /* Handle flags for the special btstq on one bit. */
1437 if (GET_CODE (SET_SRC (exp)) == ZERO_EXTRACT
1438 && XEXP (SET_SRC (exp), 1) == const1_rtx)
1440 if (CONST_INT_P (XEXP (SET_SRC (exp), 0)))
1441 /* Using cmpq. */
1442 cc_status.flags = CC_INVERTED;
1443 else
1444 /* A one-bit btstq. */
1445 cc_status.flags = CC_Z_IN_NOT_N;
1448 if (GET_CODE (SET_SRC (exp)) == COMPARE)
1450 if (!REG_P (XEXP (SET_SRC (exp), 0))
1451 && XEXP (SET_SRC (exp), 1) != const0_rtx)
1452 /* For some reason gcc will not canonicalize compare
1453 operations, reversing the sign by itself if
1454 operands are in wrong order. */
1455 /* (But NOT inverted; eq is still eq.) */
1456 cc_status.flags = CC_REVERSED;
1458 /* This seems to be overlooked by gcc. FIXME: Check again.
1459 FIXME: Is it really safe? */
1460 cc_status.value2
1461 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1462 XEXP (SET_SRC (exp), 0),
1463 XEXP (SET_SRC (exp), 1));
1465 return;
1467 else if (REG_P (SET_DEST (exp))
1468 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1469 && REG_P (XEXP (SET_DEST (exp), 0))))
1471 /* A register is set; normally CC is set to show that no
1472 test insn is needed. Catch the exceptions. */
1474 /* If not to cc0, then no "set"s in non-natural mode give
1475 ok cc0... */
1476 if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1477 || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1479 /* ... except add:s and sub:s in DImode. */
1480 if (GET_MODE (SET_DEST (exp)) == DImode
1481 && (GET_CODE (SET_SRC (exp)) == PLUS
1482 || GET_CODE (SET_SRC (exp)) == MINUS))
1484 CC_STATUS_INIT;
1485 cc_status.value1 = SET_DEST (exp);
1486 cc_status.value2 = SET_SRC (exp);
1488 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1489 cc_status.value2))
1490 cc_status.value2 = 0;
1492 /* Add and sub may set V, which gets us
1493 unoptimizable results in "gt" and "le" condition
1494 codes. */
1495 cc_status.flags |= CC_NO_OVERFLOW;
1497 return;
1500 else if (SET_SRC (exp) == const0_rtx
1501 || (REG_P (SET_SRC (exp))
1502 && (REGNO (SET_SRC (exp))
1503 > CRIS_LAST_GENERAL_REGISTER))
1504 || (TARGET_V32
1505 && GET_CODE (SET_SRC (exp)) == CONST_INT
1506 && CRIS_CONST_OK_FOR_LETTER_P (INTVAL (SET_SRC (exp)),
1507 'I')))
1509 /* There's no CC0 change for this case. Just check
1510 for overlap. */
1511 if (cc_status.value1
1512 && modified_in_p (cc_status.value1, insn))
1513 cc_status.value1 = 0;
1515 if (cc_status.value2
1516 && modified_in_p (cc_status.value2, insn))
1517 cc_status.value2 = 0;
1519 return;
1521 else
1523 CC_STATUS_INIT;
1524 cc_status.value1 = SET_DEST (exp);
1525 cc_status.value2 = SET_SRC (exp);
1527 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1528 cc_status.value2))
1529 cc_status.value2 = 0;
1531 /* Some operations may set V, which gets us
1532 unoptimizable results in "gt" and "le" condition
1533 codes. */
1534 if (GET_CODE (SET_SRC (exp)) == PLUS
1535 || GET_CODE (SET_SRC (exp)) == MINUS
1536 || GET_CODE (SET_SRC (exp)) == NEG)
1537 cc_status.flags |= CC_NO_OVERFLOW;
1539 /* For V32, nothing with a register destination sets
1540 C and V usefully. */
1541 if (TARGET_V32)
1542 cc_status.flags |= CC_NO_OVERFLOW;
1544 return;
1547 else if (MEM_P (SET_DEST (exp))
1548 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1549 && MEM_P (XEXP (SET_DEST (exp), 0))))
1551 /* When SET to MEM, then CC is not changed (except for
1552 overlap). */
1553 if (cc_status.value1
1554 && modified_in_p (cc_status.value1, insn))
1555 cc_status.value1 = 0;
1557 if (cc_status.value2
1558 && modified_in_p (cc_status.value2, insn))
1559 cc_status.value2 = 0;
1561 return;
1564 else if (GET_CODE (exp) == PARALLEL)
1566 if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1567 && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1568 && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1570 if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1571 && MEM_P (XEXP (XVECEXP (exp, 0, 0), 1)))
1573 CC_STATUS_INIT;
1575 /* For "move.S [rx=ry+o],rz", say CC reflects
1576 value1=rz and value2=[rx] */
1577 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1578 cc_status.value2
1579 = replace_equiv_address (XEXP (XVECEXP (exp, 0, 0), 1),
1580 XEXP (XVECEXP (exp, 0, 1), 0));
1582 /* Huh? A side-effect cannot change the destination
1583 register. */
1584 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1585 cc_status.value2))
1586 internal_error ("internal error: sideeffect-insn affecting main effect");
1588 /* For V32, moves to registers don't set C and V. */
1589 if (TARGET_V32)
1590 cc_status.flags |= CC_NO_OVERFLOW;
1591 return;
1593 else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1594 || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1595 && MEM_P (XEXP (XVECEXP (exp, 0, 0), 0)))
1597 /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1598 say flags are not changed, except for overlap. */
1599 if (cc_status.value1
1600 && modified_in_p (cc_status.value1, insn))
1601 cc_status.value1 = 0;
1603 if (cc_status.value2
1604 && modified_in_p (cc_status.value2, insn))
1605 cc_status.value2 = 0;
1607 return;
1612 /* If we got here, the case wasn't covered by the code above. */
1613 CC_STATUS_INIT;
1616 /* This function looks into the pattern to see how this insn affects
1617 condition codes.
1619 Used when to eliminate test insns before a condition-code user,
1620 such as a "scc" insn or a conditional branch. This includes
1621 checking if the entities that cc was updated by, are changed by the
1622 operation.
1624 Currently a jumble of the old peek-inside-the-insn and the newer
1625 check-cc-attribute methods. */
1627 void
1628 cris_notice_update_cc (rtx exp, rtx insn)
1630 enum attr_cc attrval = get_attr_cc (insn);
1632 /* Check if user specified "-mcc-init" as a bug-workaround. Remember
1633 to still set CC_REVERSED as below, since that's required by some
1634 compare insn alternatives. (FIXME: GCC should do this virtual
1635 operand swap by itself.) A test-case that may otherwise fail is
1636 gcc.c-torture/execute/20000217-1.c -O0 and -O1. */
1637 if (TARGET_CCINIT)
1639 CC_STATUS_INIT;
1641 if (attrval == CC_REV)
1642 cc_status.flags = CC_REVERSED;
1643 return;
1646 /* Slowly, we're converting to using attributes to control the setting
1647 of condition-code status. */
1648 switch (attrval)
1650 case CC_NONE:
1651 /* Even if it is "none", a setting may clobber a previous
1652 cc-value, so check. */
1653 if (GET_CODE (exp) == SET)
1655 if (cc_status.value1
1656 && modified_in_p (cc_status.value1, insn))
1657 cc_status.value1 = 0;
1659 if (cc_status.value2
1660 && modified_in_p (cc_status.value2, insn))
1661 cc_status.value2 = 0;
1663 return;
1665 case CC_CLOBBER:
1666 CC_STATUS_INIT;
1667 return;
1669 case CC_REV:
1670 case CC_NOOV32:
1671 case CC_NORMAL:
1672 cris_normal_notice_update_cc (exp, insn);
1674 /* The "test" insn doesn't clear (carry and) overflow on V32. We
1675 can change bge => bpl and blt => bmi by passing on to the cc0
1676 user that V should not be considered; bgt and ble are taken
1677 care of by other methods (see {tst,cmp}{si,hi,qi}). */
1678 if (attrval == CC_NOOV32 && TARGET_V32)
1679 cc_status.flags |= CC_NO_OVERFLOW;
1680 return;
1682 default:
1683 internal_error ("unknown cc_attr value");
1686 CC_STATUS_INIT;
1689 /* Return != 0 if the return sequence for the current function is short,
1690 like "ret" or "jump [sp+]". Prior to reloading, we can't tell if
1691 registers must be saved, so return 0 then. */
1693 bool
1694 cris_simple_epilogue (void)
1696 unsigned int regno;
1697 unsigned int reglimit = STACK_POINTER_REGNUM;
1698 bool got_really_used = false;
1700 if (! reload_completed
1701 || frame_pointer_needed
1702 || get_frame_size () != 0
1703 || crtl->args.pretend_args_size
1704 || crtl->args.size
1705 || crtl->outgoing_args_size
1706 || crtl->calls_eh_return
1708 /* If we're not supposed to emit prologue and epilogue, we must
1709 not emit return-type instructions. */
1710 || !TARGET_PROLOGUE_EPILOGUE)
1711 return false;
1713 /* Can't return from stacked return address with v32. */
1714 if (TARGET_V32 && cris_return_address_on_stack ())
1715 return false;
1717 if (crtl->uses_pic_offset_table)
1719 push_topmost_sequence ();
1720 got_really_used
1721 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
1722 pop_topmost_sequence ();
1725 /* No simple epilogue if there are saved registers. */
1726 for (regno = 0; regno < reglimit; regno++)
1727 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1728 return false;
1730 return true;
1733 /* Expand a return insn (just one insn) marked as using SRP or stack
1734 slot depending on parameter ON_STACK. */
1736 void
1737 cris_expand_return (bool on_stack)
1739 /* FIXME: emit a parallel with a USE for SRP or the stack-slot, to
1740 tell "ret" from "jump [sp+]". Some, but not all, other parts of
1741 GCC expect just (return) to do the right thing when optimizing, so
1742 we do that until they're fixed. Currently, all return insns in a
1743 function must be the same (not really a limiting factor) so we need
1744 to check that it doesn't change half-way through. */
1745 emit_jump_insn (gen_rtx_RETURN (VOIDmode));
1747 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_RET || !on_stack);
1748 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_JUMP || on_stack);
1750 cfun->machine->return_type
1751 = on_stack ? CRIS_RETINSN_JUMP : CRIS_RETINSN_RET;
1754 /* Compute a (partial) cost for rtx X. Return true if the complete
1755 cost has been computed, and false if subexpressions should be
1756 scanned. In either case, *TOTAL contains the cost result. */
1758 static bool
1759 cris_rtx_costs (rtx x, int code, int outer_code, int *total,
1760 bool speed)
1762 switch (code)
1764 case CONST_INT:
1766 HOST_WIDE_INT val = INTVAL (x);
1767 if (val == 0)
1768 *total = 0;
1769 else if (val < 32 && val >= -32)
1770 *total = 1;
1771 /* Eight or 16 bits are a word and cycle more expensive. */
1772 else if (val <= 32767 && val >= -32768)
1773 *total = 2;
1774 /* A 32-bit constant (or very seldom, unsigned 16 bits) costs
1775 another word. FIXME: This isn't linear to 16 bits. */
1776 else
1777 *total = 4;
1778 return true;
1781 case LABEL_REF:
1782 *total = 6;
1783 return true;
1785 case CONST:
1786 case SYMBOL_REF:
1787 *total = 6;
1788 return true;
1790 case CONST_DOUBLE:
1791 if (x != CONST0_RTX (GET_MODE (x) == VOIDmode ? DImode : GET_MODE (x)))
1792 *total = 12;
1793 else
1794 /* Make 0.0 cheap, else test-insns will not be used. */
1795 *total = 0;
1796 return true;
1798 case MULT:
1799 /* If we have one arm of an ADDI, make sure it gets the cost of
1800 one insn, i.e. zero cost for this operand, and just the cost
1801 of the PLUS, as the insn is created by combine from a PLUS
1802 and an ASHIFT, and the MULT cost below would make the
1803 combined value be larger than the separate insns. The insn
1804 validity is checked elsewhere by combine.
1806 FIXME: this case is a stop-gap for 4.3 and 4.4, this whole
1807 function should be rewritten. */
1808 if (outer_code == PLUS && BIAP_INDEX_P (x))
1810 *total = 0;
1811 return true;
1814 /* Identify values that are no powers of two. Powers of 2 are
1815 taken care of already and those values should not be changed. */
1816 if (!CONST_INT_P (XEXP (x, 1))
1817 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1819 /* If we have a multiply insn, then the cost is between
1820 1 and 2 "fast" instructions. */
1821 if (TARGET_HAS_MUL_INSNS)
1823 *total = COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2;
1824 return true;
1827 /* Estimate as 4 + 4 * #ofbits. */
1828 *total = COSTS_N_INSNS (132);
1829 return true;
1831 return false;
1833 case UDIV:
1834 case MOD:
1835 case UMOD:
1836 case DIV:
1837 if (!CONST_INT_P (XEXP (x, 1))
1838 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1840 /* Estimate this as 4 + 8 * #of bits. */
1841 *total = COSTS_N_INSNS (260);
1842 return true;
1844 return false;
1846 case AND:
1847 if (CONST_INT_P (XEXP (x, 1))
1848 /* Two constants may actually happen before optimization. */
1849 && !CONST_INT_P (XEXP (x, 0))
1850 && !CRIS_CONST_OK_FOR_LETTER_P (INTVAL (XEXP (x, 1)), 'I'))
1852 *total = (rtx_cost (XEXP (x, 0), outer_code, speed) + 2
1853 + 2 * GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))));
1854 return true;
1856 return false;
1858 case ZERO_EXTEND: case SIGN_EXTEND:
1859 *total = rtx_cost (XEXP (x, 0), outer_code, speed);
1860 return true;
1862 default:
1863 return false;
1867 /* The ADDRESS_COST worker. */
1869 static int
1870 cris_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
1872 /* The metric to use for the cost-macros is unclear.
1873 The metric used here is (the number of cycles needed) / 2,
1874 where we consider equal a cycle for a word of code and a cycle to
1875 read memory. FIXME: Adding "+ 1" to all values would avoid
1876 returning 0, as tree-ssa-loop-ivopts.c as of r128272 "normalizes"
1877 0 to 1, thereby giving equal costs to [rN + rM] and [rN].
1878 Unfortunately(?) such a hack would expose other pessimizations,
1879 at least with g++.dg/tree-ssa/ivopts-1.C, adding insns to the
1880 loop there, without apparent reason. */
1882 /* The cheapest addressing modes get 0, since nothing extra is needed. */
1883 if (BASE_OR_AUTOINCR_P (x))
1884 return 0;
1886 /* An indirect mem must be a DIP. This means two bytes extra for code,
1887 and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */
1888 if (MEM_P (x))
1889 return (2 + 4) / 2;
1891 /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
1892 an extra DIP prefix and 4 bytes of constant in most cases. */
1893 if (CONSTANT_P (x))
1894 return (2 + 4) / 2;
1896 /* Handle BIAP and BDAP prefixes. */
1897 if (GET_CODE (x) == PLUS)
1899 rtx tem1 = XEXP (x, 0);
1900 rtx tem2 = XEXP (x, 1);
1902 /* Local extended canonicalization rule: the first operand must
1903 be REG, unless it's an operation (MULT). */
1904 if (!REG_P (tem1) && GET_CODE (tem1) != MULT)
1905 tem1 = tem2, tem2 = XEXP (x, 0);
1907 /* We'll "assume" we have canonical RTX now. */
1908 gcc_assert (REG_P (tem1) || GET_CODE (tem1) == MULT);
1910 /* A BIAP is 2 extra bytes for the prefix insn, nothing more. We
1911 recognize the typical MULT which is always in tem1 because of
1912 insn canonicalization. */
1913 if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
1914 || REG_P (tem2))
1915 return 2 / 2;
1917 /* A BDAP (quick) is 2 extra bytes. Any constant operand to the
1918 PLUS is always found in tem2. */
1919 if (CONST_INT_P (tem2) && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
1920 return 2 / 2;
1922 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
1923 bytes. */
1924 if (CONST_INT_P (tem2)
1925 && CRIS_CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
1926 return (2 + 2) / 2;
1928 /* A BDAP with some other constant is 2 bytes extra. */
1929 if (CONSTANT_P (tem2))
1930 return (2 + 2 + 2) / 2;
1932 /* BDAP with something indirect should have a higher cost than
1933 BIAP with register. FIXME: Should it cost like a MEM or more? */
1934 return (2 + 2 + 2) / 2;
1937 /* What else? Return a high cost. It matters only for valid
1938 addressing modes. */
1939 return 10;
1942 /* Check various objections to the side-effect. Used in the test-part
1943 of an anonymous insn describing an insn with a possible side-effect.
1944 Returns nonzero if the implied side-effect is ok.
1946 code : PLUS or MULT
1947 ops : An array of rtx:es. lreg, rreg, rval,
1948 The variables multop and other_op are indexes into this,
1949 or -1 if they are not applicable.
1950 lreg : The register that gets assigned in the side-effect.
1951 rreg : One register in the side-effect expression
1952 rval : The other register, or an int.
1953 multop : An integer to multiply rval with.
1954 other_op : One of the entities of the main effect,
1955 whose mode we must consider. */
1958 cris_side_effect_mode_ok (enum rtx_code code, rtx *ops,
1959 int lreg, int rreg, int rval,
1960 int multop, int other_op)
1962 /* Find what value to multiply with, for rx =ry + rz * n. */
1963 int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
1965 rtx reg_rtx = ops[rreg];
1966 rtx val_rtx = ops[rval];
1968 /* The operands may be swapped. Canonicalize them in reg_rtx and
1969 val_rtx, where reg_rtx always is a reg (for this constraint to
1970 match). */
1971 if (! BASE_P (reg_rtx))
1972 reg_rtx = val_rtx, val_rtx = ops[rreg];
1974 /* Don't forget to check that reg_rtx really is a reg. If it isn't,
1975 we have no business. */
1976 if (! BASE_P (reg_rtx))
1977 return 0;
1979 /* Don't do this when -mno-split. */
1980 if (!TARGET_SIDE_EFFECT_PREFIXES)
1981 return 0;
1983 /* The mult expression may be hidden in lreg. FIXME: Add more
1984 commentary about that. */
1985 if (GET_CODE (val_rtx) == MULT)
1987 mult = INTVAL (XEXP (val_rtx, 1));
1988 val_rtx = XEXP (val_rtx, 0);
1989 code = MULT;
1992 /* First check the "other operand". */
1993 if (other_op >= 0)
1995 if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
1996 return 0;
1998 /* Check if the lvalue register is the same as the "other
1999 operand". If so, the result is undefined and we shouldn't do
2000 this. FIXME: Check again. */
2001 if ((BASE_P (ops[lreg])
2002 && BASE_P (ops[other_op])
2003 && REGNO (ops[lreg]) == REGNO (ops[other_op]))
2004 || rtx_equal_p (ops[other_op], ops[lreg]))
2005 return 0;
2008 /* Do not accept frame_pointer_rtx as any operand. */
2009 if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
2010 || ops[rval] == frame_pointer_rtx
2011 || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
2012 return 0;
2014 if (code == PLUS
2015 && ! BASE_P (val_rtx))
2018 /* Do not allow rx = rx + n if a normal add or sub with same size
2019 would do. */
2020 if (rtx_equal_p (ops[lreg], reg_rtx)
2021 && CONST_INT_P (val_rtx)
2022 && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2023 return 0;
2025 /* Check allowed cases, like [r(+)?].[bwd] and const. */
2026 if (CONSTANT_P (val_rtx))
2027 return 1;
2029 if (MEM_P (val_rtx) && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
2030 return 1;
2032 if (GET_CODE (val_rtx) == SIGN_EXTEND
2033 && MEM_P (XEXP (val_rtx, 0))
2034 && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
2035 return 1;
2037 /* If we got here, it's not a valid addressing mode. */
2038 return 0;
2040 else if (code == MULT
2041 || (code == PLUS && BASE_P (val_rtx)))
2043 /* Do not allow rx = rx + ry.S, since it doesn't give better code. */
2044 if (rtx_equal_p (ops[lreg], reg_rtx)
2045 || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2046 return 0;
2048 /* Do not allow bad multiply-values. */
2049 if (mult != 1 && mult != 2 && mult != 4)
2050 return 0;
2052 /* Only allow r + ... */
2053 if (! BASE_P (reg_rtx))
2054 return 0;
2056 /* If we got here, all seems ok.
2057 (All checks need to be done above). */
2058 return 1;
2061 /* If we get here, the caller got its initial tests wrong. */
2062 internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
2065 /* Whether next_cc0_user of insn is LE or GT or requires a real compare
2066 insn for other reasons. */
2068 bool
2069 cris_cc0_user_requires_cmp (rtx insn)
2071 rtx cc0_user = NULL;
2072 rtx body;
2073 rtx set;
2075 gcc_assert (insn != NULL);
2077 if (!TARGET_V32)
2078 return false;
2080 cc0_user = next_cc0_user (insn);
2081 if (cc0_user == NULL)
2082 return false;
2084 body = PATTERN (cc0_user);
2085 set = single_set (cc0_user);
2087 /* Users can be sCC and bCC. */
2088 if (JUMP_P (cc0_user)
2089 && GET_CODE (body) == SET
2090 && SET_DEST (body) == pc_rtx
2091 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2092 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx)
2094 return
2095 GET_CODE (XEXP (SET_SRC (body), 0)) == GT
2096 || GET_CODE (XEXP (SET_SRC (body), 0)) == LE;
2098 else if (set)
2100 return
2101 GET_CODE (SET_SRC (body)) == GT
2102 || GET_CODE (SET_SRC (body)) == LE;
2105 gcc_unreachable ();
2108 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2109 does not handle the case where the IN operand is strict_low_part; it
2110 does handle it for X. Test-case in Axis-20010516. This function takes
2111 care of that for THIS port. FIXME: strict_low_part is going away
2112 anyway. */
2114 static int
2115 cris_reg_overlap_mentioned_p (rtx x, rtx in)
2117 /* The function reg_overlap_mentioned now handles when X is
2118 strict_low_part, but not when IN is a STRICT_LOW_PART. */
2119 if (GET_CODE (in) == STRICT_LOW_PART)
2120 in = XEXP (in, 0);
2122 return reg_overlap_mentioned_p (x, in);
2125 /* The TARGET_ASM_NAMED_SECTION worker.
2126 We just dispatch to the functions for ELF and a.out. */
2128 void
2129 cris_target_asm_named_section (const char *name, unsigned int flags,
2130 tree decl)
2132 if (! TARGET_ELF)
2133 default_no_named_section (name, flags, decl);
2134 else
2135 default_elf_asm_named_section (name, flags, decl);
2138 /* Return TRUE iff X is a CONST valid for e.g. indexing.
2139 ANY_OPERAND is 0 if X is in a CALL_P insn or movsi, 1
2140 elsewhere. */
2142 bool
2143 cris_valid_pic_const (rtx x, bool any_operand)
2145 gcc_assert (flag_pic);
2147 switch (GET_CODE (x))
2149 case CONST_INT:
2150 case CONST_DOUBLE:
2151 return true;
2152 default:
2156 if (GET_CODE (x) != CONST)
2157 return false;
2159 x = XEXP (x, 0);
2161 /* Handle (const (plus (unspec .. UNSPEC_GOTREL) (const_int ...))). */
2162 if (GET_CODE (x) == PLUS
2163 && GET_CODE (XEXP (x, 0)) == UNSPEC
2164 && (XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREL
2165 || XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_PCREL)
2166 && CONST_INT_P (XEXP (x, 1)))
2167 x = XEXP (x, 0);
2169 if (GET_CODE (x) == UNSPEC)
2170 switch (XINT (x, 1))
2172 /* A PCREL operand is only valid for call and movsi. */
2173 case CRIS_UNSPEC_PLT_PCREL:
2174 case CRIS_UNSPEC_PCREL:
2175 return !any_operand;
2177 case CRIS_UNSPEC_PLT_GOTREL:
2178 case CRIS_UNSPEC_PLTGOTREAD:
2179 case CRIS_UNSPEC_GOTREAD:
2180 case CRIS_UNSPEC_GOTREL:
2181 return true;
2182 default:
2183 gcc_unreachable ();
2186 return cris_pic_symbol_type_of (x) == cris_no_symbol;
2189 /* Helper function to find the right PIC-type symbol to generate,
2190 given the original (non-PIC) representation. */
2192 enum cris_pic_symbol_type
2193 cris_pic_symbol_type_of (rtx x)
2195 switch (GET_CODE (x))
2197 case SYMBOL_REF:
2198 return SYMBOL_REF_LOCAL_P (x)
2199 ? cris_rel_symbol : cris_got_symbol;
2201 case LABEL_REF:
2202 return cris_rel_symbol;
2204 case CONST:
2205 return cris_pic_symbol_type_of (XEXP (x, 0));
2207 case PLUS:
2208 case MINUS:
2210 enum cris_pic_symbol_type t1 = cris_pic_symbol_type_of (XEXP (x, 0));
2211 enum cris_pic_symbol_type t2 = cris_pic_symbol_type_of (XEXP (x, 1));
2213 gcc_assert (t1 == cris_no_symbol || t2 == cris_no_symbol);
2215 if (t1 == cris_got_symbol || t1 == cris_got_symbol)
2216 return cris_got_symbol_needing_fixup;
2218 return t1 != cris_no_symbol ? t1 : t2;
2221 case CONST_INT:
2222 case CONST_DOUBLE:
2223 return cris_no_symbol;
2225 case UNSPEC:
2226 /* Likely an offsettability-test attempting to add a constant to
2227 a GOTREAD symbol, which can't be handled. */
2228 return cris_invalid_pic_symbol;
2230 default:
2231 fatal_insn ("unrecognized supposed constant", x);
2234 gcc_unreachable ();
2237 /* The LEGITIMATE_PIC_OPERAND_P worker. */
2240 cris_legitimate_pic_operand (rtx x)
2242 /* Symbols are not valid PIC operands as-is; just constants. */
2243 return cris_valid_pic_const (x, true);
2246 /* The ASM_OUTPUT_CASE_END worker. */
2248 void
2249 cris_asm_output_case_end (FILE *stream, int num, rtx table)
2251 if (TARGET_V32)
2253 rtx whole_jump_insn = PATTERN (PREV_INSN (PREV_INSN (table)));
2255 /* This can be a SEQUENCE, meaning the delay-slot of the jump is
2256 filled. */
2257 rtx parallel_jump
2258 = (GET_CODE (whole_jump_insn) == SEQUENCE
2259 ? PATTERN (XVECEXP (whole_jump_insn, 0, 0)) : whole_jump_insn);
2261 asm_fprintf (stream,
2262 "\t.word %LL%d-.%s\n",
2263 CODE_LABEL_NUMBER (XEXP (XEXP (XEXP (XVECEXP
2264 (parallel_jump, 0, 0),
2265 1), 2), 0)),
2266 (TARGET_PDEBUG ? "; default" : ""));
2267 return;
2270 asm_fprintf (stream,
2271 "\t.word %LL%d-%LL%d%s\n",
2272 CODE_LABEL_NUMBER (XEXP
2273 (XEXP
2274 (XEXP
2275 (XVECEXP
2276 (PATTERN
2277 (PREV_INSN
2278 (PREV_INSN (table))), 0, 0), 1),
2279 2), 0)),
2280 num,
2281 (TARGET_PDEBUG ? "; default" : ""));
2284 /* TARGET_HANDLE_OPTION worker. We just store the values into local
2285 variables here. Checks for correct semantics are in
2286 cris_override_options. */
2288 static bool
2289 cris_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED,
2290 int value ATTRIBUTE_UNUSED)
2292 switch (code)
2294 case OPT_metrax100:
2295 target_flags
2296 |= (MASK_SVINTO
2297 + MASK_ETRAX4_ADD
2298 + MASK_ALIGN_BY_32);
2299 break;
2301 case OPT_mno_etrax100:
2302 target_flags
2303 &= ~(MASK_SVINTO
2304 + MASK_ETRAX4_ADD
2305 + MASK_ALIGN_BY_32);
2306 break;
2308 case OPT_m32_bit:
2309 case OPT_m32bit:
2310 target_flags
2311 |= (MASK_STACK_ALIGN
2312 + MASK_CONST_ALIGN
2313 + MASK_DATA_ALIGN
2314 + MASK_ALIGN_BY_32);
2315 break;
2317 case OPT_m16_bit:
2318 case OPT_m16bit:
2319 target_flags
2320 |= (MASK_STACK_ALIGN
2321 + MASK_CONST_ALIGN
2322 + MASK_DATA_ALIGN);
2323 break;
2325 case OPT_m8_bit:
2326 case OPT_m8bit:
2327 target_flags
2328 &= ~(MASK_STACK_ALIGN
2329 + MASK_CONST_ALIGN
2330 + MASK_DATA_ALIGN);
2331 break;
2333 default:
2334 break;
2337 CRIS_SUBTARGET_HANDLE_OPTION(code, arg, value);
2339 return true;
2342 /* The OVERRIDE_OPTIONS worker.
2343 As is the norm, this also parses -mfoo=bar type parameters. */
2345 void
2346 cris_override_options (void)
2348 if (cris_max_stackframe_str)
2350 cris_max_stackframe = atoi (cris_max_stackframe_str);
2352 /* Do some sanity checking. */
2353 if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2354 internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2355 cris_max_stackframe, 0x20000000);
2358 /* Let "-metrax4" and "-metrax100" change the cpu version. */
2359 if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2360 cris_cpu_version = CRIS_CPU_SVINTO;
2361 else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2362 cris_cpu_version = CRIS_CPU_ETRAX4;
2364 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2365 if (cris_cpu_str)
2367 cris_cpu_version
2368 = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2370 if (strcmp ("etrax4", cris_cpu_str) == 0)
2371 cris_cpu_version = 3;
2373 if (strcmp ("svinto", cris_cpu_str) == 0
2374 || strcmp ("etrax100", cris_cpu_str) == 0)
2375 cris_cpu_version = 8;
2377 if (strcmp ("ng", cris_cpu_str) == 0
2378 || strcmp ("etrax100lx", cris_cpu_str) == 0)
2379 cris_cpu_version = 10;
2381 if (cris_cpu_version < 0 || cris_cpu_version > 32)
2382 error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2383 cris_cpu_str);
2385 /* Set the target flags. */
2386 if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2387 target_flags |= MASK_ETRAX4_ADD;
2389 /* If this is Svinto or higher, align for 32 bit accesses. */
2390 if (cris_cpu_version >= CRIS_CPU_SVINTO)
2391 target_flags
2392 |= (MASK_SVINTO | MASK_ALIGN_BY_32
2393 | MASK_STACK_ALIGN | MASK_CONST_ALIGN
2394 | MASK_DATA_ALIGN);
2396 /* Note that we do not add new flags when it can be completely
2397 described with a macro that uses -mcpu=X. So
2398 TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */
2401 if (cris_tune_str)
2403 int cris_tune
2404 = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2406 if (strcmp ("etrax4", cris_tune_str) == 0)
2407 cris_tune = 3;
2409 if (strcmp ("svinto", cris_tune_str) == 0
2410 || strcmp ("etrax100", cris_tune_str) == 0)
2411 cris_tune = 8;
2413 if (strcmp ("ng", cris_tune_str) == 0
2414 || strcmp ("etrax100lx", cris_tune_str) == 0)
2415 cris_tune = 10;
2417 if (cris_tune < 0 || cris_tune > 32)
2418 error ("unknown CRIS cpu version specification in -mtune= : %s",
2419 cris_tune_str);
2421 if (cris_tune >= CRIS_CPU_SVINTO)
2422 /* We have currently nothing more to tune than alignment for
2423 memory accesses. */
2424 target_flags
2425 |= (MASK_STACK_ALIGN | MASK_CONST_ALIGN
2426 | MASK_DATA_ALIGN | MASK_ALIGN_BY_32);
2429 if (cris_cpu_version >= CRIS_CPU_V32)
2430 target_flags &= ~(MASK_SIDE_EFFECT_PREFIXES|MASK_MUL_BUG);
2432 if (flag_pic)
2434 /* Use error rather than warning, so invalid use is easily
2435 detectable. Still change to the values we expect, to avoid
2436 further errors. */
2437 if (! TARGET_LINUX)
2439 error ("-fPIC and -fpic are not supported in this configuration");
2440 flag_pic = 0;
2443 /* Turn off function CSE. We need to have the addresses reach the
2444 call expanders to get PLT-marked, as they could otherwise be
2445 compared against zero directly or indirectly. After visiting the
2446 call expanders they will then be cse:ed, as the call expanders
2447 force_reg the addresses, effectively forcing flag_no_function_cse
2448 to 0. */
2449 flag_no_function_cse = 1;
2452 if (write_symbols == DWARF2_DEBUG && ! TARGET_ELF)
2454 warning (0, "that particular -g option is invalid with -maout and -melinux");
2455 write_symbols = DBX_DEBUG;
2458 /* Set the per-function-data initializer. */
2459 init_machine_status = cris_init_machine_status;
2462 /* The TARGET_ASM_OUTPUT_MI_THUNK worker. */
2464 static void
2465 cris_asm_output_mi_thunk (FILE *stream,
2466 tree thunkdecl ATTRIBUTE_UNUSED,
2467 HOST_WIDE_INT delta,
2468 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
2469 tree funcdecl)
2471 if (delta > 0)
2472 fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2473 ADDITIVE_SIZE_MODIFIER (delta), delta,
2474 reg_names[CRIS_FIRST_ARG_REG]);
2475 else if (delta < 0)
2476 fprintf (stream, "\tsub%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2477 ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2478 reg_names[CRIS_FIRST_ARG_REG]);
2480 if (flag_pic)
2482 const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2484 name = (* targetm.strip_name_encoding) (name);
2486 if (TARGET_V32)
2488 fprintf (stream, "\tba ");
2489 assemble_name (stream, name);
2490 fprintf (stream, "%s\n", CRIS_PLT_PCOFFSET_SUFFIX);
2492 else
2494 fprintf (stream, "add.d ");
2495 assemble_name (stream, name);
2496 fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2499 else
2501 fprintf (stream, "jump ");
2502 assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2503 fprintf (stream, "\n");
2505 if (TARGET_V32)
2506 fprintf (stream, "\tnop\n");
2510 /* Boilerplate emitted at start of file.
2512 NO_APP *only at file start* means faster assembly. It also means
2513 comments are not allowed. In some cases comments will be output
2514 for debugging purposes. Make sure they are allowed then.
2516 We want a .file directive only if TARGET_ELF. */
2517 static void
2518 cris_file_start (void)
2520 /* These expressions can vary at run time, so we cannot put
2521 them into TARGET_INITIALIZER. */
2522 targetm.file_start_app_off = !(TARGET_PDEBUG || flag_print_asm_name);
2523 targetm.file_start_file_directive = TARGET_ELF;
2525 default_file_start ();
2528 /* Rename the function calls for integer multiply and divide. */
2529 static void
2530 cris_init_libfuncs (void)
2532 set_optab_libfunc (smul_optab, SImode, "__Mul");
2533 set_optab_libfunc (sdiv_optab, SImode, "__Div");
2534 set_optab_libfunc (udiv_optab, SImode, "__Udiv");
2535 set_optab_libfunc (smod_optab, SImode, "__Mod");
2536 set_optab_libfunc (umod_optab, SImode, "__Umod");
2539 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2540 mark functions. */
2542 void
2543 cris_init_expanders (void)
2545 /* Nothing here at the moment. */
2548 /* Zero initialization is OK for all current fields. */
2550 static struct machine_function *
2551 cris_init_machine_status (void)
2553 return GGC_CNEW (struct machine_function);
2556 /* Split a 2 word move (DI or presumably DF) into component parts.
2557 Originally a copy of gen_split_move_double in m32r.c. */
2560 cris_split_movdx (rtx *operands)
2562 enum machine_mode mode = GET_MODE (operands[0]);
2563 rtx dest = operands[0];
2564 rtx src = operands[1];
2565 rtx val;
2567 /* We used to have to handle (SUBREG (MEM)) here, but that should no
2568 longer happen; after reload there are no SUBREGs any more, and we're
2569 only called after reload. */
2570 CRIS_ASSERT (GET_CODE (dest) != SUBREG && GET_CODE (src) != SUBREG);
2572 start_sequence ();
2573 if (REG_P (dest))
2575 int dregno = REGNO (dest);
2577 /* Reg-to-reg copy. */
2578 if (REG_P (src))
2580 int sregno = REGNO (src);
2582 int reverse = (dregno == sregno + 1);
2584 /* We normally copy the low-numbered register first. However, if
2585 the first register operand 0 is the same as the second register of
2586 operand 1, we must copy in the opposite order. */
2587 emit_insn (gen_rtx_SET (VOIDmode,
2588 operand_subword (dest, reverse, TRUE, mode),
2589 operand_subword (src, reverse, TRUE, mode)));
2591 emit_insn (gen_rtx_SET (VOIDmode,
2592 operand_subword (dest, !reverse, TRUE, mode),
2593 operand_subword (src, !reverse, TRUE, mode)));
2595 /* Constant-to-reg copy. */
2596 else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE)
2598 rtx words[2];
2599 split_double (src, &words[0], &words[1]);
2600 emit_insn (gen_rtx_SET (VOIDmode,
2601 operand_subword (dest, 0, TRUE, mode),
2602 words[0]));
2604 emit_insn (gen_rtx_SET (VOIDmode,
2605 operand_subword (dest, 1, TRUE, mode),
2606 words[1]));
2608 /* Mem-to-reg copy. */
2609 else if (MEM_P (src))
2611 /* If the high-address word is used in the address, we must load it
2612 last. Otherwise, load it first. */
2613 rtx addr = XEXP (src, 0);
2614 int reverse
2615 = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2617 /* The original code implies that we can't do
2618 move.x [rN+],rM move.x [rN],rM+1
2619 when rN is dead, because of REG_NOTES damage. That is
2620 consistent with what I've seen, so don't try it.
2622 We have two different cases here; if the addr is POST_INC,
2623 just pass it through, otherwise add constants. */
2625 if (GET_CODE (addr) == POST_INC)
2627 rtx mem;
2628 rtx insn;
2630 /* Whenever we emit insns with post-incremented
2631 addresses ourselves, we must add a post-inc note
2632 manually. */
2633 mem = change_address (src, SImode, addr);
2634 insn
2635 = gen_rtx_SET (VOIDmode,
2636 operand_subword (dest, 0, TRUE, mode), mem);
2637 insn = emit_insn (insn);
2638 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2639 REG_NOTES (insn)
2640 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2641 REG_NOTES (insn));
2643 mem = copy_rtx (mem);
2644 insn
2645 = gen_rtx_SET (VOIDmode,
2646 operand_subword (dest, 1, 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 else
2655 /* Make sure we don't get any other addresses with
2656 embedded postincrements. They should be stopped in
2657 GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2658 safety. */
2659 if (side_effects_p (addr))
2660 fatal_insn ("unexpected side-effects in address", addr);
2662 emit_insn (gen_rtx_SET
2663 (VOIDmode,
2664 operand_subword (dest, reverse, TRUE, mode),
2665 change_address
2666 (src, SImode,
2667 plus_constant (addr,
2668 reverse * UNITS_PER_WORD))));
2669 emit_insn (gen_rtx_SET
2670 (VOIDmode,
2671 operand_subword (dest, ! reverse, TRUE, mode),
2672 change_address
2673 (src, SImode,
2674 plus_constant (addr,
2675 (! reverse) *
2676 UNITS_PER_WORD))));
2679 else
2680 internal_error ("Unknown src");
2682 /* Reg-to-mem copy or clear mem. */
2683 else if (MEM_P (dest)
2684 && (REG_P (src)
2685 || src == const0_rtx
2686 || src == CONST0_RTX (DFmode)))
2688 rtx addr = XEXP (dest, 0);
2690 if (GET_CODE (addr) == POST_INC)
2692 rtx mem;
2693 rtx insn;
2695 /* Whenever we emit insns with post-incremented addresses
2696 ourselves, we must add a post-inc note manually. */
2697 mem = change_address (dest, SImode, addr);
2698 insn
2699 = gen_rtx_SET (VOIDmode,
2700 mem, operand_subword (src, 0, TRUE, mode));
2701 insn = emit_insn (insn);
2702 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2703 REG_NOTES (insn)
2704 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2705 REG_NOTES (insn));
2707 mem = copy_rtx (mem);
2708 insn
2709 = gen_rtx_SET (VOIDmode,
2710 mem,
2711 operand_subword (src, 1, TRUE, mode));
2712 insn = emit_insn (insn);
2713 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2714 REG_NOTES (insn)
2715 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2716 REG_NOTES (insn));
2718 else
2720 /* Make sure we don't get any other addresses with embedded
2721 postincrements. They should be stopped in
2722 GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */
2723 if (side_effects_p (addr))
2724 fatal_insn ("unexpected side-effects in address", addr);
2726 emit_insn (gen_rtx_SET
2727 (VOIDmode,
2728 change_address (dest, SImode, addr),
2729 operand_subword (src, 0, TRUE, mode)));
2731 emit_insn (gen_rtx_SET
2732 (VOIDmode,
2733 change_address (dest, SImode,
2734 plus_constant (addr,
2735 UNITS_PER_WORD)),
2736 operand_subword (src, 1, TRUE, mode)));
2740 else
2741 internal_error ("Unknown dest");
2743 val = get_insns ();
2744 end_sequence ();
2745 return val;
2748 /* The expander for the prologue pattern name. */
2750 void
2751 cris_expand_prologue (void)
2753 int regno;
2754 int size = get_frame_size ();
2755 /* Shorten the used name for readability. */
2756 int cfoa_size = crtl->outgoing_args_size;
2757 int last_movem_reg = -1;
2758 int framesize = 0;
2759 rtx mem, insn;
2760 int return_address_on_stack = cris_return_address_on_stack ();
2761 int got_really_used = false;
2762 int n_movem_regs = 0;
2763 int pretend = crtl->args.pretend_args_size;
2765 /* Don't do anything if no prologues or epilogues are wanted. */
2766 if (!TARGET_PROLOGUE_EPILOGUE)
2767 return;
2769 CRIS_ASSERT (size >= 0);
2771 if (crtl->uses_pic_offset_table)
2773 /* A reference may have been optimized out (like the abort () in
2774 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
2775 it's still used. */
2776 push_topmost_sequence ();
2777 got_really_used
2778 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
2779 pop_topmost_sequence ();
2782 /* Align the size to what's best for the CPU model. */
2783 if (TARGET_STACK_ALIGN)
2784 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
2786 if (pretend)
2788 /* See also cris_setup_incoming_varargs where
2789 cfun->machine->stdarg_regs is set. There are other setters of
2790 crtl->args.pretend_args_size than stdarg handling, like
2791 for an argument passed with parts in R13 and stack. We must
2792 not store R13 into the pretend-area for that case, as GCC does
2793 that itself. "Our" store would be marked as redundant and GCC
2794 will attempt to remove it, which will then be flagged as an
2795 internal error; trying to remove a frame-related insn. */
2796 int stdarg_regs = cfun->machine->stdarg_regs;
2798 framesize += pretend;
2800 for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
2801 stdarg_regs > 0;
2802 regno--, pretend -= 4, stdarg_regs--)
2804 insn = emit_insn (gen_rtx_SET (VOIDmode,
2805 stack_pointer_rtx,
2806 plus_constant (stack_pointer_rtx,
2807 -4)));
2808 /* FIXME: When dwarf2 frame output and unless asynchronous
2809 exceptions, make dwarf2 bundle together all stack
2810 adjustments like it does for registers between stack
2811 adjustments. */
2812 RTX_FRAME_RELATED_P (insn) = 1;
2814 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2815 set_mem_alias_set (mem, get_varargs_alias_set ());
2816 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2818 /* Note the absence of RTX_FRAME_RELATED_P on the above insn:
2819 the value isn't restored, so we don't want to tell dwarf2
2820 that it's been stored to stack, else EH handling info would
2821 get confused. */
2824 /* For other setters of crtl->args.pretend_args_size, we
2825 just adjust the stack by leaving the remaining size in
2826 "pretend", handled below. */
2829 /* Save SRP if not a leaf function. */
2830 if (return_address_on_stack)
2832 insn = emit_insn (gen_rtx_SET (VOIDmode,
2833 stack_pointer_rtx,
2834 plus_constant (stack_pointer_rtx,
2835 -4 - pretend)));
2836 pretend = 0;
2837 RTX_FRAME_RELATED_P (insn) = 1;
2839 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2840 set_mem_alias_set (mem, get_frame_alias_set ());
2841 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM));
2842 RTX_FRAME_RELATED_P (insn) = 1;
2843 framesize += 4;
2846 /* Set up the frame pointer, if needed. */
2847 if (frame_pointer_needed)
2849 insn = emit_insn (gen_rtx_SET (VOIDmode,
2850 stack_pointer_rtx,
2851 plus_constant (stack_pointer_rtx,
2852 -4 - pretend)));
2853 pretend = 0;
2854 RTX_FRAME_RELATED_P (insn) = 1;
2856 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2857 set_mem_alias_set (mem, get_frame_alias_set ());
2858 insn = emit_move_insn (mem, frame_pointer_rtx);
2859 RTX_FRAME_RELATED_P (insn) = 1;
2861 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
2862 RTX_FRAME_RELATED_P (insn) = 1;
2864 framesize += 4;
2867 /* Between frame-pointer and saved registers lie the area for local
2868 variables. If we get here with "pretended" size remaining, count
2869 it into the general stack size. */
2870 size += pretend;
2872 /* Get a contiguous sequence of registers, starting with R0, that need
2873 to be saved. */
2874 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
2876 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
2878 n_movem_regs++;
2880 /* Check if movem may be used for registers so far. */
2881 if (regno == last_movem_reg + 1)
2882 /* Yes, update next expected register. */
2883 last_movem_reg = regno;
2884 else
2886 /* We cannot use movem for all registers. We have to flush
2887 any movem:ed registers we got so far. */
2888 if (last_movem_reg != -1)
2890 int n_saved
2891 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2893 /* It is a win to use a side-effect assignment for
2894 64 <= size <= 128. But side-effect on movem was
2895 not usable for CRIS v0..3. Also only do it if
2896 side-effects insns are allowed. */
2897 if ((last_movem_reg + 1) * 4 + size >= 64
2898 && (last_movem_reg + 1) * 4 + size <= 128
2899 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2900 && TARGET_SIDE_EFFECT_PREFIXES)
2903 = gen_rtx_MEM (SImode,
2904 plus_constant (stack_pointer_rtx,
2905 -(n_saved * 4 + size)));
2906 set_mem_alias_set (mem, get_frame_alias_set ());
2907 insn
2908 = cris_emit_movem_store (mem, GEN_INT (n_saved),
2909 -(n_saved * 4 + size),
2910 true);
2912 else
2914 insn
2915 = gen_rtx_SET (VOIDmode,
2916 stack_pointer_rtx,
2917 plus_constant (stack_pointer_rtx,
2918 -(n_saved * 4 + size)));
2919 insn = emit_insn (insn);
2920 RTX_FRAME_RELATED_P (insn) = 1;
2922 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2923 set_mem_alias_set (mem, get_frame_alias_set ());
2924 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2925 0, true);
2928 framesize += n_saved * 4 + size;
2929 last_movem_reg = -1;
2930 size = 0;
2933 insn = emit_insn (gen_rtx_SET (VOIDmode,
2934 stack_pointer_rtx,
2935 plus_constant (stack_pointer_rtx,
2936 -4 - size)));
2937 RTX_FRAME_RELATED_P (insn) = 1;
2939 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2940 set_mem_alias_set (mem, get_frame_alias_set ());
2941 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2942 RTX_FRAME_RELATED_P (insn) = 1;
2944 framesize += 4 + size;
2945 size = 0;
2950 /* Check after, if we could movem all registers. This is the normal case. */
2951 if (last_movem_reg != -1)
2953 int n_saved
2954 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2956 /* Side-effect on movem was not usable for CRIS v0..3. Also only
2957 do it if side-effects insns are allowed. */
2958 if ((last_movem_reg + 1) * 4 + size >= 64
2959 && (last_movem_reg + 1) * 4 + size <= 128
2960 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2961 && TARGET_SIDE_EFFECT_PREFIXES)
2964 = gen_rtx_MEM (SImode,
2965 plus_constant (stack_pointer_rtx,
2966 -(n_saved * 4 + size)));
2967 set_mem_alias_set (mem, get_frame_alias_set ());
2968 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2969 -(n_saved * 4 + size), true);
2971 else
2973 insn
2974 = gen_rtx_SET (VOIDmode,
2975 stack_pointer_rtx,
2976 plus_constant (stack_pointer_rtx,
2977 -(n_saved * 4 + size)));
2978 insn = emit_insn (insn);
2979 RTX_FRAME_RELATED_P (insn) = 1;
2981 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2982 set_mem_alias_set (mem, get_frame_alias_set ());
2983 insn = cris_emit_movem_store (mem, GEN_INT (n_saved), 0, true);
2986 framesize += n_saved * 4 + size;
2987 /* We have to put outgoing argument space after regs. */
2988 if (cfoa_size)
2990 insn = emit_insn (gen_rtx_SET (VOIDmode,
2991 stack_pointer_rtx,
2992 plus_constant (stack_pointer_rtx,
2993 -cfoa_size)));
2994 RTX_FRAME_RELATED_P (insn) = 1;
2995 framesize += cfoa_size;
2998 else if ((size + cfoa_size) > 0)
3000 insn = emit_insn (gen_rtx_SET (VOIDmode,
3001 stack_pointer_rtx,
3002 plus_constant (stack_pointer_rtx,
3003 -(cfoa_size + size))));
3004 RTX_FRAME_RELATED_P (insn) = 1;
3005 framesize += size + cfoa_size;
3008 /* Set up the PIC register, if it is used. */
3009 if (got_really_used)
3011 rtx got
3012 = gen_rtx_UNSPEC (SImode, gen_rtvec (1, const0_rtx), CRIS_UNSPEC_GOT);
3013 emit_move_insn (pic_offset_table_rtx, got);
3015 /* FIXME: This is a cover-up for flow2 messing up; it doesn't
3016 follow exceptional paths and tries to delete the GOT load as
3017 unused, if it isn't used on the non-exceptional paths. Other
3018 ports have similar or other cover-ups, or plain bugs marking
3019 the GOT register load as maybe-dead. To see this, remove the
3020 line below and try libsupc++/vec.cc or a trivial
3021 "static void y (); void x () {try {y ();} catch (...) {}}". */
3022 emit_use (pic_offset_table_rtx);
3025 if (cris_max_stackframe && framesize > cris_max_stackframe)
3026 warning (0, "stackframe too big: %d bytes", framesize);
3029 /* The expander for the epilogue pattern. */
3031 void
3032 cris_expand_epilogue (void)
3034 int regno;
3035 int size = get_frame_size ();
3036 int last_movem_reg = -1;
3037 int argspace_offset = crtl->outgoing_args_size;
3038 int pretend = crtl->args.pretend_args_size;
3039 rtx mem;
3040 bool return_address_on_stack = cris_return_address_on_stack ();
3041 /* A reference may have been optimized out
3042 (like the abort () in fde_split in unwind-dw2-fde.c, at least 3.2.1)
3043 so check that it's still used. */
3044 int got_really_used = false;
3045 int n_movem_regs = 0;
3047 if (!TARGET_PROLOGUE_EPILOGUE)
3048 return;
3050 if (crtl->uses_pic_offset_table)
3052 /* A reference may have been optimized out (like the abort () in
3053 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
3054 it's still used. */
3055 push_topmost_sequence ();
3056 got_really_used
3057 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
3058 pop_topmost_sequence ();
3061 /* Align byte count of stack frame. */
3062 if (TARGET_STACK_ALIGN)
3063 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
3065 /* Check how many saved regs we can movem. They start at r0 and must
3066 be contiguous. */
3067 for (regno = 0;
3068 regno < FIRST_PSEUDO_REGISTER;
3069 regno++)
3070 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3072 n_movem_regs++;
3074 if (regno == last_movem_reg + 1)
3075 last_movem_reg = regno;
3076 else
3077 break;
3080 /* If there was only one register that really needed to be saved
3081 through movem, don't use movem. */
3082 if (n_movem_regs == 1)
3083 last_movem_reg = -1;
3085 /* Now emit "normal" move insns for all regs higher than the movem
3086 regs. */
3087 for (regno = FIRST_PSEUDO_REGISTER - 1;
3088 regno > last_movem_reg;
3089 regno--)
3090 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3092 rtx insn;
3094 if (argspace_offset)
3096 /* There is an area for outgoing parameters located before
3097 the saved registers. We have to adjust for that. */
3098 emit_insn (gen_rtx_SET (VOIDmode,
3099 stack_pointer_rtx,
3100 plus_constant (stack_pointer_rtx,
3101 argspace_offset)));
3102 /* Make sure we only do this once. */
3103 argspace_offset = 0;
3106 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3107 stack_pointer_rtx));
3108 set_mem_alias_set (mem, get_frame_alias_set ());
3109 insn = emit_move_insn (gen_rtx_raw_REG (SImode, regno), mem);
3111 /* Whenever we emit insns with post-incremented addresses
3112 ourselves, we must add a post-inc note manually. */
3113 REG_NOTES (insn)
3114 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3117 /* If we have any movem-restore, do it now. */
3118 if (last_movem_reg != -1)
3120 rtx insn;
3122 if (argspace_offset)
3124 emit_insn (gen_rtx_SET (VOIDmode,
3125 stack_pointer_rtx,
3126 plus_constant (stack_pointer_rtx,
3127 argspace_offset)));
3128 argspace_offset = 0;
3131 mem = gen_rtx_MEM (SImode,
3132 gen_rtx_POST_INC (SImode, stack_pointer_rtx));
3133 set_mem_alias_set (mem, get_frame_alias_set ());
3134 insn
3135 = emit_insn (cris_gen_movem_load (mem,
3136 GEN_INT (last_movem_reg + 1), 0));
3137 /* Whenever we emit insns with post-incremented addresses
3138 ourselves, we must add a post-inc note manually. */
3139 if (side_effects_p (PATTERN (insn)))
3140 REG_NOTES (insn)
3141 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3144 /* If we don't clobber all of the allocated stack area (we've already
3145 deallocated saved registers), GCC might want to schedule loads from
3146 the stack to *after* the stack-pointer restore, which introduces an
3147 interrupt race condition. This happened for the initial-value
3148 SRP-restore for g++.dg/eh/registers1.C (noticed by inspection of
3149 other failure for that test). It also happened for the stack slot
3150 for the return value in (one version of)
3151 linux/fs/dcache.c:__d_lookup, at least with "-O2
3152 -fno-omit-frame-pointer". */
3154 /* Restore frame pointer if necessary. */
3155 if (frame_pointer_needed)
3157 rtx insn;
3159 emit_insn (gen_cris_frame_deallocated_barrier ());
3161 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
3162 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3163 stack_pointer_rtx));
3164 set_mem_alias_set (mem, get_frame_alias_set ());
3165 insn = emit_move_insn (frame_pointer_rtx, mem);
3167 /* Whenever we emit insns with post-incremented addresses
3168 ourselves, we must add a post-inc note manually. */
3169 REG_NOTES (insn)
3170 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3172 else if ((size + argspace_offset) != 0)
3174 emit_insn (gen_cris_frame_deallocated_barrier ());
3176 /* If there was no frame-pointer to restore sp from, we must
3177 explicitly deallocate local variables. */
3179 /* Handle space for outgoing parameters that hasn't been handled
3180 yet. */
3181 size += argspace_offset;
3183 emit_insn (gen_rtx_SET (VOIDmode,
3184 stack_pointer_rtx,
3185 plus_constant (stack_pointer_rtx, size)));
3188 /* If this function has no pushed register parameters
3189 (stdargs/varargs), and if it is not a leaf function, then we have
3190 the return address on the stack. */
3191 if (return_address_on_stack && pretend == 0)
3193 if (TARGET_V32 || crtl->calls_eh_return)
3195 rtx mem;
3196 rtx insn;
3197 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3198 mem = gen_rtx_MEM (SImode,
3199 gen_rtx_POST_INC (SImode,
3200 stack_pointer_rtx));
3201 set_mem_alias_set (mem, get_frame_alias_set ());
3202 insn = emit_move_insn (srpreg, mem);
3204 /* Whenever we emit insns with post-incremented addresses
3205 ourselves, we must add a post-inc note manually. */
3206 REG_NOTES (insn)
3207 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3209 if (crtl->calls_eh_return)
3210 emit_insn (gen_addsi3 (stack_pointer_rtx,
3211 stack_pointer_rtx,
3212 gen_rtx_raw_REG (SImode,
3213 CRIS_STACKADJ_REG)));
3214 cris_expand_return (false);
3216 else
3217 cris_expand_return (true);
3219 return;
3222 /* If we pushed some register parameters, then adjust the stack for
3223 them. */
3224 if (pretend != 0)
3226 /* If SRP is stored on the way, we need to restore it first. */
3227 if (return_address_on_stack)
3229 rtx mem;
3230 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3231 rtx insn;
3233 mem = gen_rtx_MEM (SImode,
3234 gen_rtx_POST_INC (SImode,
3235 stack_pointer_rtx));
3236 set_mem_alias_set (mem, get_frame_alias_set ());
3237 insn = emit_move_insn (srpreg, mem);
3239 /* Whenever we emit insns with post-incremented addresses
3240 ourselves, we must add a post-inc note manually. */
3241 REG_NOTES (insn)
3242 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3245 emit_insn (gen_rtx_SET (VOIDmode,
3246 stack_pointer_rtx,
3247 plus_constant (stack_pointer_rtx, pretend)));
3250 /* Perform the "physical" unwinding that the EH machinery calculated. */
3251 if (crtl->calls_eh_return)
3252 emit_insn (gen_addsi3 (stack_pointer_rtx,
3253 stack_pointer_rtx,
3254 gen_rtx_raw_REG (SImode,
3255 CRIS_STACKADJ_REG)));
3256 cris_expand_return (false);
3259 /* Worker function for generating movem from mem for load_multiple. */
3262 cris_gen_movem_load (rtx src, rtx nregs_rtx, int nprefix)
3264 int nregs = INTVAL (nregs_rtx);
3265 rtvec vec;
3266 int eltno = 1;
3267 int i;
3268 rtx srcreg = XEXP (src, 0);
3269 unsigned int regno = nregs - 1;
3270 int regno_inc = -1;
3272 if (TARGET_V32)
3274 regno = 0;
3275 regno_inc = 1;
3278 if (GET_CODE (srcreg) == POST_INC)
3279 srcreg = XEXP (srcreg, 0);
3281 CRIS_ASSERT (REG_P (srcreg));
3283 /* Don't use movem for just one insn. The insns are equivalent except
3284 for the pipeline hazard (on v32); movem does not forward the loaded
3285 registers so there's a three cycles penalty for their use. */
3286 if (nregs == 1)
3287 return gen_movsi (gen_rtx_REG (SImode, 0), src);
3289 vec = rtvec_alloc (nprefix + nregs
3290 + (GET_CODE (XEXP (src, 0)) == POST_INC));
3292 if (GET_CODE (XEXP (src, 0)) == POST_INC)
3294 RTVEC_ELT (vec, nprefix + 1)
3295 = gen_rtx_SET (VOIDmode, srcreg, plus_constant (srcreg, nregs * 4));
3296 eltno++;
3299 src = replace_equiv_address (src, srcreg);
3300 RTVEC_ELT (vec, nprefix)
3301 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno), src);
3302 regno += regno_inc;
3304 for (i = 1; i < nregs; i++, eltno++)
3306 RTVEC_ELT (vec, nprefix + eltno)
3307 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno),
3308 adjust_address_nv (src, SImode, i * 4));
3309 regno += regno_inc;
3312 return gen_rtx_PARALLEL (VOIDmode, vec);
3315 /* Worker function for generating movem to mem. If FRAME_RELATED, notes
3316 are added that the dwarf2 machinery understands. */
3319 cris_emit_movem_store (rtx dest, rtx nregs_rtx, int increment,
3320 bool frame_related)
3322 int nregs = INTVAL (nregs_rtx);
3323 rtvec vec;
3324 int eltno = 1;
3325 int i;
3326 rtx insn;
3327 rtx destreg = XEXP (dest, 0);
3328 unsigned int regno = nregs - 1;
3329 int regno_inc = -1;
3331 if (TARGET_V32)
3333 regno = 0;
3334 regno_inc = 1;
3337 if (GET_CODE (destreg) == POST_INC)
3338 increment += nregs * 4;
3340 if (GET_CODE (destreg) == POST_INC || GET_CODE (destreg) == PLUS)
3341 destreg = XEXP (destreg, 0);
3343 CRIS_ASSERT (REG_P (destreg));
3345 /* Don't use movem for just one insn. The insns are equivalent except
3346 for the pipeline hazard (on v32); movem does not forward the loaded
3347 registers so there's a three cycles penalty for use. */
3348 if (nregs == 1)
3350 rtx mov = gen_rtx_SET (VOIDmode, dest, gen_rtx_REG (SImode, 0));
3352 if (increment == 0)
3354 insn = emit_insn (mov);
3355 if (frame_related)
3356 RTX_FRAME_RELATED_P (insn) = 1;
3357 return insn;
3360 /* If there was a request for a side-effect, create the ordinary
3361 parallel. */
3362 vec = rtvec_alloc (2);
3364 RTVEC_ELT (vec, 0) = mov;
3365 RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, destreg,
3366 plus_constant (destreg, increment));
3367 if (frame_related)
3369 RTX_FRAME_RELATED_P (mov) = 1;
3370 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3373 else
3375 vec = rtvec_alloc (nregs + (increment != 0 ? 1 : 0));
3376 RTVEC_ELT (vec, 0)
3377 = gen_rtx_SET (VOIDmode,
3378 replace_equiv_address (dest,
3379 plus_constant (destreg,
3380 increment)),
3381 gen_rtx_REG (SImode, regno));
3382 regno += regno_inc;
3384 /* The dwarf2 info wants this mark on each component in a parallel
3385 that's part of the prologue (though it's optional on the first
3386 component). */
3387 if (frame_related)
3388 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 0)) = 1;
3390 if (increment != 0)
3392 RTVEC_ELT (vec, 1)
3393 = gen_rtx_SET (VOIDmode, destreg,
3394 plus_constant (destreg,
3395 increment != 0
3396 ? increment : nregs * 4));
3397 eltno++;
3399 if (frame_related)
3400 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3402 /* Don't call adjust_address_nv on a post-incremented address if
3403 we can help it. */
3404 if (GET_CODE (XEXP (dest, 0)) == POST_INC)
3405 dest = replace_equiv_address (dest, destreg);
3408 for (i = 1; i < nregs; i++, eltno++)
3410 RTVEC_ELT (vec, eltno)
3411 = gen_rtx_SET (VOIDmode, adjust_address_nv (dest, SImode, i * 4),
3412 gen_rtx_REG (SImode, regno));
3413 if (frame_related)
3414 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, eltno)) = 1;
3415 regno += regno_inc;
3419 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, vec));
3421 /* Because dwarf2out.c handles the insns in a parallel as a sequence,
3422 we need to keep the stack adjustment separate, after the
3423 MEM-setters. Else the stack-adjustment in the second component of
3424 the parallel would be mishandled; the offsets for the SETs that
3425 follow it would be wrong. We prepare for this by adding a
3426 REG_FRAME_RELATED_EXPR with the MEM-setting parts in a SEQUENCE
3427 followed by the increment. Note that we have FRAME_RELATED_P on
3428 all the SETs, including the original stack adjustment SET in the
3429 parallel. */
3430 if (frame_related)
3432 if (increment != 0)
3434 rtx seq = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nregs + 1));
3435 XVECEXP (seq, 0, 0) = copy_rtx (XVECEXP (PATTERN (insn), 0, 0));
3436 for (i = 1; i < nregs; i++)
3437 XVECEXP (seq, 0, i)
3438 = copy_rtx (XVECEXP (PATTERN (insn), 0, i + 1));
3439 XVECEXP (seq, 0, nregs) = copy_rtx (XVECEXP (PATTERN (insn), 0, 1));
3440 REG_NOTES (insn)
3441 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, seq,
3442 REG_NOTES (insn));
3445 RTX_FRAME_RELATED_P (insn) = 1;
3448 return insn;
3451 /* Worker function for expanding the address for PIC function calls. */
3453 void
3454 cris_expand_pic_call_address (rtx *opp)
3456 rtx op = *opp;
3458 gcc_assert (MEM_P (op));
3459 op = XEXP (op, 0);
3461 /* It might be that code can be generated that jumps to 0 (or to a
3462 specific address). Don't die on that. (There is a
3463 testcase.) */
3464 if (CONSTANT_ADDRESS_P (op) && !CONST_INT_P (op))
3466 enum cris_pic_symbol_type t = cris_pic_symbol_type_of (op);
3468 CRIS_ASSERT (can_create_pseudo_p ());
3470 /* For local symbols (non-PLT), just get the plain symbol
3471 reference into a register. For symbols that can be PLT, make
3472 them PLT. */
3473 if (t == cris_rel_symbol)
3475 /* For v32, we're fine as-is; just PICify the symbol. Forcing
3476 into a register caused performance regression for 3.2.1,
3477 observable in __floatdidf and elsewhere in libgcc. */
3478 if (TARGET_V32)
3480 rtx sym = GET_CODE (op) != CONST ? op : get_related_value (op);
3481 HOST_WIDE_INT offs = get_integer_term (op);
3483 /* We can't get calls to sym+N, N integer, can we? */
3484 gcc_assert (offs == 0);
3486 op = gen_rtx_CONST (Pmode,
3487 gen_rtx_UNSPEC (Pmode, gen_rtvec (1, sym),
3488 CRIS_UNSPEC_PCREL));
3490 else
3491 op = force_reg (Pmode, op);
3493 else if (t == cris_got_symbol)
3495 if (TARGET_AVOID_GOTPLT)
3497 /* Change a "jsr sym" into (allocate register rM, rO)
3498 "move.d (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_GOTREL)),rM"
3499 "add.d rPIC,rM,rO", "jsr rO" for pre-v32 and
3500 "jsr (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_PCREL))"
3501 for v32. */
3502 rtx tem, rm, ro;
3503 gcc_assert (can_create_pseudo_p ());
3504 crtl->uses_pic_offset_table = 1;
3505 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3506 TARGET_V32
3507 ? CRIS_UNSPEC_PLT_PCREL
3508 : CRIS_UNSPEC_PLT_GOTREL);
3509 tem = gen_rtx_CONST (Pmode, tem);
3510 if (TARGET_V32)
3511 op = tem;
3512 else
3514 rm = gen_reg_rtx (Pmode);
3515 emit_move_insn (rm, tem);
3516 ro = gen_reg_rtx (Pmode);
3517 if (expand_binop (Pmode, add_optab, rm,
3518 pic_offset_table_rtx,
3519 ro, 0, OPTAB_LIB_WIDEN) != ro)
3520 internal_error ("expand_binop failed in movsi got");
3521 op = ro;
3524 else
3526 /* Change a "jsr sym" into (allocate register rM, rO)
3527 "move.d (const (unspec [sym] CRIS_UNSPEC_PLTGOTREAD)),rM"
3528 "add.d rPIC,rM,rO" "jsr [rO]" with the memory access
3529 marked as not trapping and not aliasing. No "move.d
3530 [rO],rP" as that would invite to re-use of a value
3531 that should not be reused. FIXME: Need a peephole2
3532 for cases when this is cse:d from the call, to change
3533 back to just get the PLT entry address, so we don't
3534 resolve the same symbol over and over (the memory
3535 access of the PLTGOT isn't constant). */
3536 rtx tem, mem, rm, ro;
3538 gcc_assert (can_create_pseudo_p ());
3539 crtl->uses_pic_offset_table = 1;
3540 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3541 CRIS_UNSPEC_PLTGOTREAD);
3542 rm = gen_reg_rtx (Pmode);
3543 emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
3544 ro = gen_reg_rtx (Pmode);
3545 if (expand_binop (Pmode, add_optab, rm,
3546 pic_offset_table_rtx,
3547 ro, 0, OPTAB_LIB_WIDEN) != ro)
3548 internal_error ("expand_binop failed in movsi got");
3549 mem = gen_rtx_MEM (Pmode, ro);
3551 /* This MEM doesn't alias anything. Whether it aliases
3552 other same symbols is unimportant. */
3553 set_mem_alias_set (mem, new_alias_set ());
3554 MEM_NOTRAP_P (mem) = 1;
3555 op = mem;
3558 else
3559 /* Can't possibly get a GOT-needing-fixup for a function-call,
3560 right? */
3561 fatal_insn ("Unidentifiable call op", op);
3563 *opp = replace_equiv_address (*opp, op);
3567 /* Make sure operands are in the right order for an addsi3 insn as
3568 generated by a define_split. Nothing but REG_P as the first
3569 operand is recognized by addsi3 after reload. OPERANDS contains
3570 the operands, with the first at OPERANDS[N] and the second at
3571 OPERANDS[N+1]. */
3573 void
3574 cris_order_for_addsi3 (rtx *operands, int n)
3576 if (!REG_P (operands[n]))
3578 rtx tem = operands[n];
3579 operands[n] = operands[n + 1];
3580 operands[n + 1] = tem;
3584 /* Use from within code, from e.g. PRINT_OPERAND and
3585 PRINT_OPERAND_ADDRESS. Macros used in output_addr_const need to emit
3586 different things depending on whether code operand or constant is
3587 emitted. */
3589 static void
3590 cris_output_addr_const (FILE *file, rtx x)
3592 in_code++;
3593 output_addr_const (file, x);
3594 in_code--;
3597 /* Worker function for ASM_OUTPUT_SYMBOL_REF. */
3599 void
3600 cris_asm_output_symbol_ref (FILE *file, rtx x)
3602 gcc_assert (GET_CODE (x) == SYMBOL_REF);
3604 if (flag_pic && in_code > 0)
3606 const char *origstr = XSTR (x, 0);
3607 const char *str;
3608 str = (* targetm.strip_name_encoding) (origstr);
3609 assemble_name (file, str);
3611 /* Sanity check. */
3612 if (!TARGET_V32 && !crtl->uses_pic_offset_table)
3613 output_operand_lossage ("PIC register isn't set up");
3615 else
3616 assemble_name (file, XSTR (x, 0));
3619 /* Worker function for ASM_OUTPUT_LABEL_REF. */
3621 void
3622 cris_asm_output_label_ref (FILE *file, char *buf)
3624 if (flag_pic && in_code > 0)
3626 assemble_name (file, buf);
3628 /* Sanity check. */
3629 if (!TARGET_V32 && !crtl->uses_pic_offset_table)
3630 internal_error ("emitting PIC operand, but PIC register isn't set up");
3632 else
3633 assemble_name (file, buf);
3636 /* Worker function for OUTPUT_ADDR_CONST_EXTRA. */
3638 bool
3639 cris_output_addr_const_extra (FILE *file, rtx xconst)
3641 switch (GET_CODE (xconst))
3643 rtx x;
3645 case UNSPEC:
3646 x = XVECEXP (xconst, 0, 0);
3647 CRIS_ASSERT (GET_CODE (x) == SYMBOL_REF
3648 || GET_CODE (x) == LABEL_REF
3649 || GET_CODE (x) == CONST);
3650 output_addr_const (file, x);
3651 switch (XINT (xconst, 1))
3653 case CRIS_UNSPEC_PCREL:
3654 /* We only get this with -fpic/PIC to tell it apart from an
3655 invalid symbol. We can't tell here, but it should only
3656 be the operand of a call or movsi. */
3657 gcc_assert (TARGET_V32 && flag_pic);
3658 break;
3660 case CRIS_UNSPEC_PLT_PCREL:
3661 gcc_assert (TARGET_V32);
3662 fprintf (file, ":PLT");
3663 break;
3665 case CRIS_UNSPEC_PLT_GOTREL:
3666 gcc_assert (!TARGET_V32);
3667 fprintf (file, ":PLTG");
3668 break;
3670 case CRIS_UNSPEC_GOTREL:
3671 gcc_assert (!TARGET_V32);
3672 fprintf (file, ":GOTOFF");
3673 break;
3675 case CRIS_UNSPEC_GOTREAD:
3676 if (flag_pic == 1)
3677 fprintf (file, ":GOT16");
3678 else
3679 fprintf (file, ":GOT");
3680 break;
3682 case CRIS_UNSPEC_PLTGOTREAD:
3683 if (flag_pic == 1)
3684 fprintf (file, CRIS_GOTPLT_SUFFIX "16");
3685 else
3686 fprintf (file, CRIS_GOTPLT_SUFFIX);
3687 break;
3689 default:
3690 gcc_unreachable ();
3692 return true;
3694 default:
3695 return false;
3699 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3701 static rtx
3702 cris_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3703 int incoming ATTRIBUTE_UNUSED)
3705 return gen_rtx_REG (Pmode, CRIS_STRUCT_VALUE_REGNUM);
3708 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
3710 static void
3711 cris_setup_incoming_varargs (CUMULATIVE_ARGS *ca,
3712 enum machine_mode mode ATTRIBUTE_UNUSED,
3713 tree type ATTRIBUTE_UNUSED,
3714 int *pretend_arg_size,
3715 int second_time)
3717 if (ca->regs < CRIS_MAX_ARGS_IN_REGS)
3719 int stdarg_regs = CRIS_MAX_ARGS_IN_REGS - ca->regs;
3720 cfun->machine->stdarg_regs = stdarg_regs;
3721 *pretend_arg_size = stdarg_regs * 4;
3724 if (TARGET_PDEBUG)
3725 fprintf (asm_out_file,
3726 "\n; VA:: ANSI: %d args before, anon @ #%d, %dtime\n",
3727 ca->regs, *pretend_arg_size, second_time);
3730 /* Return true if TYPE must be passed by invisible reference.
3731 For cris, we pass <= 8 bytes by value, others by reference. */
3733 static bool
3734 cris_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
3735 enum machine_mode mode, const_tree type,
3736 bool named ATTRIBUTE_UNUSED)
3738 return (targetm.calls.must_pass_in_stack (mode, type)
3739 || CRIS_FUNCTION_ARG_SIZE (mode, type) > 8);
3743 static int
3744 cris_arg_partial_bytes (CUMULATIVE_ARGS *ca, enum machine_mode mode,
3745 tree type, bool named ATTRIBUTE_UNUSED)
3747 if (ca->regs == CRIS_MAX_ARGS_IN_REGS - 1
3748 && !targetm.calls.must_pass_in_stack (mode, type)
3749 && CRIS_FUNCTION_ARG_SIZE (mode, type) > 4
3750 && CRIS_FUNCTION_ARG_SIZE (mode, type) <= 8)
3751 return UNITS_PER_WORD;
3752 else
3753 return 0;
3756 /* Worker function for TARGET_MD_ASM_CLOBBERS. */
3758 static tree
3759 cris_md_asm_clobbers (tree outputs, tree inputs, tree in_clobbers)
3761 HARD_REG_SET mof_set;
3762 tree clobbers;
3763 tree t;
3765 CLEAR_HARD_REG_SET (mof_set);
3766 SET_HARD_REG_BIT (mof_set, CRIS_MOF_REGNUM);
3768 /* For the time being, all asms clobber condition codes. Revisit when
3769 there's a reasonable use for inputs/outputs that mention condition
3770 codes. */
3771 clobbers
3772 = tree_cons (NULL_TREE,
3773 build_string (strlen (reg_names[CRIS_CC0_REGNUM]),
3774 reg_names[CRIS_CC0_REGNUM]),
3775 in_clobbers);
3777 for (t = outputs; t != NULL; t = TREE_CHAIN (t))
3779 tree val = TREE_VALUE (t);
3781 /* The constraint letter for the singleton register class of MOF
3782 is 'h'. If it's mentioned in the constraints, the asm is
3783 MOF-aware and adding it to the clobbers would cause it to have
3784 impossible constraints. */
3785 if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
3786 'h') != NULL
3787 || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
3788 return clobbers;
3791 for (t = inputs; t != NULL; t = TREE_CHAIN (t))
3793 tree val = TREE_VALUE (t);
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 return tree_cons (NULL_TREE,
3802 build_string (strlen (reg_names[CRIS_MOF_REGNUM]),
3803 reg_names[CRIS_MOF_REGNUM]),
3804 clobbers);
3807 #if 0
3808 /* Various small functions to replace macros. Only called from a
3809 debugger. They might collide with gcc functions or system functions,
3810 so only emit them when '#if 1' above. */
3812 enum rtx_code Get_code (rtx);
3814 enum rtx_code
3815 Get_code (rtx x)
3817 return GET_CODE (x);
3820 const char *Get_mode (rtx);
3822 const char *
3823 Get_mode (rtx x)
3825 return GET_MODE_NAME (GET_MODE (x));
3828 rtx Xexp (rtx, int);
3831 Xexp (rtx x, int n)
3833 return XEXP (x, n);
3836 rtx Xvecexp (rtx, int, int);
3839 Xvecexp (rtx x, int n, int m)
3841 return XVECEXP (x, n, m);
3844 int Get_rtx_len (rtx);
3847 Get_rtx_len (rtx x)
3849 return GET_RTX_LENGTH (GET_CODE (x));
3852 /* Use upper-case to distinguish from local variables that are sometimes
3853 called next_insn and prev_insn. */
3855 rtx Next_insn (rtx);
3858 Next_insn (rtx insn)
3860 return NEXT_INSN (insn);
3863 rtx Prev_insn (rtx);
3866 Prev_insn (rtx insn)
3868 return PREV_INSN (insn);
3870 #endif
3872 #include "gt-cris.h"
3875 * Local variables:
3876 * eval: (c-set-style "gnu")
3877 * indent-tabs-mode: t
3878 * End: