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