Rebase.
[official-gcc.git] / gcc / config / fr30 / fr30.c
blob37759cc7bd4325947849d9e55abfe9edc4f8b404
1 /* FR30 specific functions.
2 Copyright (C) 1998-2014 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /*{{{ Includes */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "recog.h"
35 #include "tree.h"
36 #include "stor-layout.h"
37 #include "varasm.h"
38 #include "output.h"
39 #include "expr.h"
40 #include "obstack.h"
41 #include "except.h"
42 #include "function.h"
43 #include "df.h"
44 #include "diagnostic-core.h"
45 #include "tm_p.h"
46 #include "target.h"
47 #include "target-def.h"
48 #include "builtins.h"
50 /*}}}*/
51 /*{{{ Function Prologues & Epilogues */
53 /* The FR30 stack looks like this:
55 Before call After call
56 FP ->| | | |
57 +-----------------------+ +-----------------------+ high
58 | | | | memory
59 | local variables, | | local variables, |
60 | reg save area, etc. | | reg save area, etc. |
61 | | | |
62 +-----------------------+ +-----------------------+
63 | | | |
64 | args to the func that | | args to this func. |
65 | is being called that | | |
66 SP ->| do not fit in regs | | |
67 +-----------------------+ +-----------------------+
68 | args that used to be | \
69 | in regs; only created | | pretend_size
70 AP-> | for vararg funcs | /
71 +-----------------------+
72 | | \
73 | register save area | |
74 | | |
75 +-----------------------+ | reg_size
76 | return address | |
77 +-----------------------+ |
78 FP ->| previous frame ptr | /
79 +-----------------------+
80 | | \
81 | local variables | | var_size
82 | | /
83 +-----------------------+
84 | | \
85 low | room for args to | |
86 memory | other funcs called | | args_size
87 | from this one | |
88 SP ->| | /
89 +-----------------------+
91 Note, AP is a fake hard register. It will be eliminated in favor of
92 SP or FP as appropriate.
94 Note, Some or all of the stack sections above may be omitted if they
95 are not needed. */
97 /* Structure to be filled in by fr30_compute_frame_size() with register
98 save masks, and offsets for the current function. */
99 struct fr30_frame_info
101 unsigned int total_size; /* # Bytes that the entire frame takes up. */
102 unsigned int pretend_size; /* # Bytes we push and pretend caller did. */
103 unsigned int args_size; /* # Bytes that outgoing arguments take up. */
104 unsigned int reg_size; /* # Bytes needed to store regs. */
105 unsigned int var_size; /* # Bytes that variables take up. */
106 unsigned int frame_size; /* # Bytes in current frame. */
107 unsigned int gmask; /* Mask of saved registers. */
108 unsigned int save_fp; /* Nonzero if frame pointer must be saved. */
109 unsigned int save_rp; /* Nonzero if return pointer must be saved. */
110 int initialised; /* Nonzero if frame size already calculated. */
113 /* Current frame information calculated by fr30_compute_frame_size(). */
114 static struct fr30_frame_info current_frame_info;
116 /* Zero structure to initialize current_frame_info. */
117 static struct fr30_frame_info zero_frame_info;
119 static void fr30_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
120 tree, int *, int);
121 static bool fr30_must_pass_in_stack (enum machine_mode, const_tree);
122 static int fr30_arg_partial_bytes (cumulative_args_t, enum machine_mode,
123 tree, bool);
124 static rtx fr30_function_arg (cumulative_args_t, enum machine_mode,
125 const_tree, bool);
126 static void fr30_function_arg_advance (cumulative_args_t, enum machine_mode,
127 const_tree, bool);
128 static bool fr30_frame_pointer_required (void);
129 static rtx fr30_function_value (const_tree, const_tree, bool);
130 static rtx fr30_libcall_value (enum machine_mode, const_rtx);
131 static bool fr30_function_value_regno_p (const unsigned int);
132 static bool fr30_can_eliminate (const int, const int);
133 static void fr30_asm_trampoline_template (FILE *);
134 static void fr30_trampoline_init (rtx, tree, rtx);
135 static int fr30_num_arg_regs (enum machine_mode, const_tree);
137 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
138 #define RETURN_POINTER_MASK (1 << (RETURN_POINTER_REGNUM))
140 /* Tell prologue and epilogue if register REGNO should be saved / restored.
141 The return address and frame pointer are treated separately.
142 Don't consider them here. */
143 #define MUST_SAVE_REGISTER(regno) \
144 ( (regno) != RETURN_POINTER_REGNUM \
145 && (regno) != FRAME_POINTER_REGNUM \
146 && df_regs_ever_live_p (regno) \
147 && ! call_used_regs [regno] )
149 #define MUST_SAVE_FRAME_POINTER (df_regs_ever_live_p (FRAME_POINTER_REGNUM) || frame_pointer_needed)
150 #define MUST_SAVE_RETURN_POINTER (df_regs_ever_live_p (RETURN_POINTER_REGNUM) || crtl->profile)
152 #if UNITS_PER_WORD == 4
153 #define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
154 #endif
156 /* Initialize the GCC target structure. */
157 #undef TARGET_ASM_ALIGNED_HI_OP
158 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
159 #undef TARGET_ASM_ALIGNED_SI_OP
160 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
162 #undef TARGET_PROMOTE_PROTOTYPES
163 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
164 #undef TARGET_PASS_BY_REFERENCE
165 #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
166 #undef TARGET_ARG_PARTIAL_BYTES
167 #define TARGET_ARG_PARTIAL_BYTES fr30_arg_partial_bytes
168 #undef TARGET_FUNCTION_ARG
169 #define TARGET_FUNCTION_ARG fr30_function_arg
170 #undef TARGET_FUNCTION_ARG_ADVANCE
171 #define TARGET_FUNCTION_ARG_ADVANCE fr30_function_arg_advance
173 #undef TARGET_FUNCTION_VALUE
174 #define TARGET_FUNCTION_VALUE fr30_function_value
175 #undef TARGET_LIBCALL_VALUE
176 #define TARGET_LIBCALL_VALUE fr30_libcall_value
177 #undef TARGET_FUNCTION_VALUE_REGNO_P
178 #define TARGET_FUNCTION_VALUE_REGNO_P fr30_function_value_regno_p
180 #undef TARGET_SETUP_INCOMING_VARARGS
181 #define TARGET_SETUP_INCOMING_VARARGS fr30_setup_incoming_varargs
182 #undef TARGET_MUST_PASS_IN_STACK
183 #define TARGET_MUST_PASS_IN_STACK fr30_must_pass_in_stack
185 #undef TARGET_FRAME_POINTER_REQUIRED
186 #define TARGET_FRAME_POINTER_REQUIRED fr30_frame_pointer_required
188 #undef TARGET_CAN_ELIMINATE
189 #define TARGET_CAN_ELIMINATE fr30_can_eliminate
191 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
192 #define TARGET_ASM_TRAMPOLINE_TEMPLATE fr30_asm_trampoline_template
193 #undef TARGET_TRAMPOLINE_INIT
194 #define TARGET_TRAMPOLINE_INIT fr30_trampoline_init
196 struct gcc_target targetm = TARGET_INITIALIZER;
199 /* Worker function for TARGET_CAN_ELIMINATE. */
201 bool
202 fr30_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
204 return (to == FRAME_POINTER_REGNUM || ! frame_pointer_needed);
207 /* Returns the number of bytes offset between FROM_REG and TO_REG
208 for the current function. As a side effect it fills in the
209 current_frame_info structure, if the data is available. */
210 unsigned int
211 fr30_compute_frame_size (int from_reg, int to_reg)
213 int regno;
214 unsigned int return_value;
215 unsigned int var_size;
216 unsigned int args_size;
217 unsigned int pretend_size;
218 unsigned int reg_size;
219 unsigned int gmask;
221 var_size = WORD_ALIGN (get_frame_size ());
222 args_size = WORD_ALIGN (crtl->outgoing_args_size);
223 pretend_size = crtl->args.pretend_args_size;
225 reg_size = 0;
226 gmask = 0;
228 /* Calculate space needed for registers. */
229 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++)
231 if (MUST_SAVE_REGISTER (regno))
233 reg_size += UNITS_PER_WORD;
234 gmask |= 1 << regno;
238 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
239 current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER;
241 reg_size += (current_frame_info.save_fp + current_frame_info.save_rp)
242 * UNITS_PER_WORD;
244 /* Save computed information. */
245 current_frame_info.pretend_size = pretend_size;
246 current_frame_info.var_size = var_size;
247 current_frame_info.args_size = args_size;
248 current_frame_info.reg_size = reg_size;
249 current_frame_info.frame_size = args_size + var_size;
250 current_frame_info.total_size = args_size + var_size + reg_size + pretend_size;
251 current_frame_info.gmask = gmask;
252 current_frame_info.initialised = reload_completed;
254 /* Calculate the required distance. */
255 return_value = 0;
257 if (to_reg == STACK_POINTER_REGNUM)
258 return_value += args_size + var_size;
260 if (from_reg == ARG_POINTER_REGNUM)
261 return_value += reg_size;
263 return return_value;
266 /* Called after register allocation to add any instructions needed for the
267 prologue. Using a prologue insn is favored compared to putting all of the
268 instructions in output_function_prologue(), since it allows the scheduler
269 to intermix instructions with the saves of the caller saved registers. In
270 some cases, it might be necessary to emit a barrier instruction as the last
271 insn to prevent such scheduling. */
273 void
274 fr30_expand_prologue (void)
276 int regno;
277 rtx insn;
279 if (! current_frame_info.initialised)
280 fr30_compute_frame_size (0, 0);
282 /* This cases shouldn't happen. Catch it now. */
283 gcc_assert (current_frame_info.total_size || !current_frame_info.gmask);
285 /* Allocate space for register arguments if this is a variadic function. */
286 if (current_frame_info.pretend_size)
288 int regs_to_save = current_frame_info.pretend_size / UNITS_PER_WORD;
290 /* Push argument registers into the pretend arg area. */
291 for (regno = FIRST_ARG_REGNUM + FR30_NUM_ARG_REGS; regno --, regs_to_save --;)
293 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
294 RTX_FRAME_RELATED_P (insn) = 1;
298 if (current_frame_info.gmask)
300 /* Save any needed call-saved regs. */
301 for (regno = STACK_POINTER_REGNUM; regno--;)
303 if ((current_frame_info.gmask & (1 << regno)) != 0)
305 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
306 RTX_FRAME_RELATED_P (insn) = 1;
311 /* Save return address if necessary. */
312 if (current_frame_info.save_rp)
314 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode,
315 RETURN_POINTER_REGNUM)));
316 RTX_FRAME_RELATED_P (insn) = 1;
319 /* Save old frame pointer and create new one, if necessary. */
320 if (current_frame_info.save_fp)
322 if (current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
324 int enter_size = current_frame_info.frame_size + UNITS_PER_WORD;
325 rtx pattern;
327 insn = emit_insn (gen_enter_func (GEN_INT (enter_size)));
328 RTX_FRAME_RELATED_P (insn) = 1;
330 pattern = PATTERN (insn);
332 /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
333 if (GET_CODE (pattern) == PARALLEL)
335 int x;
336 for (x = XVECLEN (pattern, 0); x--;)
338 rtx part = XVECEXP (pattern, 0, x);
340 /* One of the insns in the ENTER pattern updates the
341 frame pointer. If we do not actually need the frame
342 pointer in this function then this is a side effect
343 rather than a desired effect, so we do not mark that
344 insn as being related to the frame set up. Doing this
345 allows us to compile the crash66.C test file in the
346 G++ testsuite. */
347 if (! frame_pointer_needed
348 && GET_CODE (part) == SET
349 && SET_DEST (part) == hard_frame_pointer_rtx)
350 RTX_FRAME_RELATED_P (part) = 0;
351 else
352 RTX_FRAME_RELATED_P (part) = 1;
356 else
358 insn = emit_insn (gen_movsi_push (frame_pointer_rtx));
359 RTX_FRAME_RELATED_P (insn) = 1;
361 if (frame_pointer_needed)
363 insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
364 RTX_FRAME_RELATED_P (insn) = 1;
369 /* Allocate the stack frame. */
370 if (current_frame_info.frame_size == 0)
371 ; /* Nothing to do. */
372 else if (current_frame_info.save_fp
373 && current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
374 ; /* Nothing to do. */
375 else if (current_frame_info.frame_size <= 512)
377 insn = emit_insn (gen_add_to_stack
378 (GEN_INT (- (signed) current_frame_info.frame_size)));
379 RTX_FRAME_RELATED_P (insn) = 1;
381 else
383 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
384 insn = emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
385 RTX_FRAME_RELATED_P (insn) = 1;
386 insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
387 RTX_FRAME_RELATED_P (insn) = 1;
390 if (crtl->profile)
391 emit_insn (gen_blockage ());
394 /* Called after register allocation to add any instructions needed for the
395 epilogue. Using an epilogue insn is favored compared to putting all of the
396 instructions in output_function_epilogue(), since it allows the scheduler
397 to intermix instructions with the restores of the caller saved registers.
398 In some cases, it might be necessary to emit a barrier instruction as the
399 first insn to prevent such scheduling. */
400 void
401 fr30_expand_epilogue (void)
403 int regno;
405 /* Perform the inversion operations of the prologue. */
406 gcc_assert (current_frame_info.initialised);
408 /* Pop local variables and arguments off the stack.
409 If frame_pointer_needed is TRUE then the frame pointer register
410 has actually been used as a frame pointer, and we can recover
411 the stack pointer from it, otherwise we must unwind the stack
412 manually. */
413 if (current_frame_info.frame_size > 0)
415 if (current_frame_info.save_fp && frame_pointer_needed)
417 emit_insn (gen_leave_func ());
418 current_frame_info.save_fp = 0;
420 else if (current_frame_info.frame_size <= 508)
421 emit_insn (gen_add_to_stack
422 (GEN_INT (current_frame_info.frame_size)));
423 else
425 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
426 emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
427 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
431 if (current_frame_info.save_fp)
432 emit_insn (gen_movsi_pop (frame_pointer_rtx));
434 /* Pop all the registers that were pushed. */
435 if (current_frame_info.save_rp)
436 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, RETURN_POINTER_REGNUM)));
438 for (regno = 0; regno < STACK_POINTER_REGNUM; regno ++)
439 if (current_frame_info.gmask & (1 << regno))
440 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno)));
442 if (current_frame_info.pretend_size)
443 emit_insn (gen_add_to_stack (GEN_INT (current_frame_info.pretend_size)));
445 /* Reset state info for each function. */
446 current_frame_info = zero_frame_info;
448 emit_jump_insn (gen_return_from_func ());
451 /* Do any needed setup for a variadic function. We must create a register
452 parameter block, and then copy any anonymous arguments, plus the last
453 named argument, from registers into memory. * copying actually done in
454 fr30_expand_prologue().
456 ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
457 which has type TYPE and mode MODE, and we rely on this fact. */
458 void
459 fr30_setup_incoming_varargs (cumulative_args_t arg_regs_used_so_far_v,
460 enum machine_mode mode,
461 tree type ATTRIBUTE_UNUSED,
462 int *pretend_size,
463 int second_time ATTRIBUTE_UNUSED)
465 CUMULATIVE_ARGS *arg_regs_used_so_far
466 = get_cumulative_args (arg_regs_used_so_far_v);
467 int size;
469 /* All BLKmode values are passed by reference. */
470 gcc_assert (mode != BLKmode);
472 /* ??? This run-time test as well as the code inside the if
473 statement is probably unnecessary. */
474 if (targetm.calls.strict_argument_naming (arg_regs_used_so_far_v))
475 /* If TARGET_STRICT_ARGUMENT_NAMING returns true, then the last named
476 arg must not be treated as an anonymous arg. */
477 /* ??? This is a pointer increment, which makes no sense. */
478 arg_regs_used_so_far += fr30_num_arg_regs (mode, type);
480 size = FR30_NUM_ARG_REGS - (* arg_regs_used_so_far);
482 if (size <= 0)
483 return;
485 * pretend_size = (size * UNITS_PER_WORD);
488 /*}}}*/
489 /*{{{ Printing operands */
491 /* Print a memory address as an operand to reference that memory location. */
493 void
494 fr30_print_operand_address (FILE *stream, rtx address)
496 switch (GET_CODE (address))
498 case SYMBOL_REF:
499 output_addr_const (stream, address);
500 break;
502 default:
503 fprintf (stderr, "code = %x\n", GET_CODE (address));
504 debug_rtx (address);
505 output_operand_lossage ("fr30_print_operand_address: unhandled address");
506 break;
510 /* Print an operand. */
512 void
513 fr30_print_operand (FILE *file, rtx x, int code)
515 rtx x0;
517 switch (code)
519 case '#':
520 /* Output a :D if this instruction is delayed. */
521 if (dbr_sequence_length () != 0)
522 fputs (":D", file);
523 return;
525 case 'p':
526 /* Compute the register name of the second register in a hi/lo
527 register pair. */
528 if (GET_CODE (x) != REG)
529 output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
530 else
531 fprintf (file, "r%d", REGNO (x) + 1);
532 return;
534 case 'b':
535 /* Convert GCC's comparison operators into FR30 comparison codes. */
536 switch (GET_CODE (x))
538 case EQ: fprintf (file, "eq"); break;
539 case NE: fprintf (file, "ne"); break;
540 case LT: fprintf (file, "lt"); break;
541 case LE: fprintf (file, "le"); break;
542 case GT: fprintf (file, "gt"); break;
543 case GE: fprintf (file, "ge"); break;
544 case LTU: fprintf (file, "c"); break;
545 case LEU: fprintf (file, "ls"); break;
546 case GTU: fprintf (file, "hi"); break;
547 case GEU: fprintf (file, "nc"); break;
548 default:
549 output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
550 break;
552 return;
554 case 'B':
555 /* Convert GCC's comparison operators into the complimentary FR30
556 comparison codes. */
557 switch (GET_CODE (x))
559 case EQ: fprintf (file, "ne"); break;
560 case NE: fprintf (file, "eq"); break;
561 case LT: fprintf (file, "ge"); break;
562 case LE: fprintf (file, "gt"); break;
563 case GT: fprintf (file, "le"); break;
564 case GE: fprintf (file, "lt"); break;
565 case LTU: fprintf (file, "nc"); break;
566 case LEU: fprintf (file, "hi"); break;
567 case GTU: fprintf (file, "ls"); break;
568 case GEU: fprintf (file, "c"); break;
569 default:
570 output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
571 break;
573 return;
575 case 'A':
576 /* Print a signed byte value as an unsigned value. */
577 if (GET_CODE (x) != CONST_INT)
578 output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
579 else
581 HOST_WIDE_INT val;
583 val = INTVAL (x);
585 val &= 0xff;
587 fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
589 return;
591 case 'x':
592 if (GET_CODE (x) != CONST_INT
593 || INTVAL (x) < 16
594 || INTVAL (x) > 32)
595 output_operand_lossage ("fr30_print_operand: invalid %%x code");
596 else
597 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) - 16);
598 return;
600 case 'F':
601 if (GET_CODE (x) != CONST_DOUBLE)
602 output_operand_lossage ("fr30_print_operand: invalid %%F code");
603 else
605 char str[30];
607 real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x),
608 sizeof (str), 0, 1);
609 fputs (str, file);
611 return;
613 case 0:
614 /* Handled below. */
615 break;
617 default:
618 fprintf (stderr, "unknown code = %x\n", code);
619 output_operand_lossage ("fr30_print_operand: unknown code");
620 return;
623 switch (GET_CODE (x))
625 case REG:
626 fputs (reg_names [REGNO (x)], file);
627 break;
629 case MEM:
630 x0 = XEXP (x,0);
632 switch (GET_CODE (x0))
634 case REG:
635 gcc_assert ((unsigned) REGNO (x0) < ARRAY_SIZE (reg_names));
636 fprintf (file, "@%s", reg_names [REGNO (x0)]);
637 break;
639 case PLUS:
640 if (GET_CODE (XEXP (x0, 0)) != REG
641 || REGNO (XEXP (x0, 0)) < FRAME_POINTER_REGNUM
642 || REGNO (XEXP (x0, 0)) > STACK_POINTER_REGNUM
643 || GET_CODE (XEXP (x0, 1)) != CONST_INT)
645 fprintf (stderr, "bad INDEXed address:");
646 debug_rtx (x);
647 output_operand_lossage ("fr30_print_operand: unhandled MEM");
649 else if (REGNO (XEXP (x0, 0)) == FRAME_POINTER_REGNUM)
651 HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
652 if (val < -(1 << 9) || val > ((1 << 9) - 4))
654 fprintf (stderr, "frame INDEX out of range:");
655 debug_rtx (x);
656 output_operand_lossage ("fr30_print_operand: unhandled MEM");
658 fprintf (file, "@(r14, #" HOST_WIDE_INT_PRINT_DEC ")", val);
660 else
662 HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
663 if (val < 0 || val > ((1 << 6) - 4))
665 fprintf (stderr, "stack INDEX out of range:");
666 debug_rtx (x);
667 output_operand_lossage ("fr30_print_operand: unhandled MEM");
669 fprintf (file, "@(r15, #" HOST_WIDE_INT_PRINT_DEC ")", val);
671 break;
673 case SYMBOL_REF:
674 output_address (x0);
675 break;
677 default:
678 fprintf (stderr, "bad MEM code = %x\n", GET_CODE (x0));
679 debug_rtx (x);
680 output_operand_lossage ("fr30_print_operand: unhandled MEM");
681 break;
683 break;
685 case CONST_DOUBLE :
686 /* We handle SFmode constants here as output_addr_const doesn't. */
687 if (GET_MODE (x) == SFmode)
689 REAL_VALUE_TYPE d;
690 long l;
692 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
693 REAL_VALUE_TO_TARGET_SINGLE (d, l);
694 fprintf (file, "0x%08lx", l);
695 break;
698 /* Fall through. Let output_addr_const deal with it. */
699 default:
700 output_addr_const (file, x);
701 break;
704 return;
707 /*}}}*/
709 /* Implements TARGET_FUNCTION_VALUE. */
711 static rtx
712 fr30_function_value (const_tree valtype,
713 const_tree fntype_or_decli ATTRIBUTE_UNUSED,
714 bool outgoing ATTRIBUTE_UNUSED)
716 return gen_rtx_REG (TYPE_MODE (valtype), RETURN_VALUE_REGNUM);
719 /* Implements TARGET_LIBCALL_VALUE. */
721 static rtx
722 fr30_libcall_value (enum machine_mode mode,
723 const_rtx fun ATTRIBUTE_UNUSED)
725 return gen_rtx_REG (mode, RETURN_VALUE_REGNUM);
728 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
730 static bool
731 fr30_function_value_regno_p (const unsigned int regno)
733 return (regno == RETURN_VALUE_REGNUM);
736 /*{{{ Function arguments */
738 /* Return true if we should pass an argument on the stack rather than
739 in registers. */
741 static bool
742 fr30_must_pass_in_stack (enum machine_mode mode, const_tree type)
744 if (mode == BLKmode)
745 return true;
746 if (type == NULL)
747 return false;
748 return AGGREGATE_TYPE_P (type);
751 /* Compute the number of word sized registers needed to hold a
752 function argument of mode INT_MODE and tree type TYPE. */
753 static int
754 fr30_num_arg_regs (enum machine_mode mode, const_tree type)
756 int size;
758 if (targetm.calls.must_pass_in_stack (mode, type))
759 return 0;
761 if (type && mode == BLKmode)
762 size = int_size_in_bytes (type);
763 else
764 size = GET_MODE_SIZE (mode);
766 return (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
769 /* Returns the number of bytes in which *part* of a parameter of machine
770 mode MODE and tree type TYPE (which may be NULL if the type is not known).
771 If the argument fits entirely in the argument registers, or entirely on
772 the stack, then 0 is returned.
773 CUM is the number of argument registers already used by earlier
774 parameters to the function. */
776 static int
777 fr30_arg_partial_bytes (cumulative_args_t cum_v, enum machine_mode mode,
778 tree type, bool named)
780 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
782 /* Unnamed arguments, i.e. those that are prototyped as ...
783 are always passed on the stack.
784 Also check here to see if all the argument registers are full. */
785 if (named == 0 || *cum >= FR30_NUM_ARG_REGS)
786 return 0;
788 /* Work out how many argument registers would be needed if this
789 parameter were to be passed entirely in registers. If there
790 are sufficient argument registers available (or if no registers
791 are needed because the parameter must be passed on the stack)
792 then return zero, as this parameter does not require partial
793 register, partial stack stack space. */
794 if (*cum + fr30_num_arg_regs (mode, type) <= FR30_NUM_ARG_REGS)
795 return 0;
797 return (FR30_NUM_ARG_REGS - *cum) * UNITS_PER_WORD;
800 static rtx
801 fr30_function_arg (cumulative_args_t cum_v, enum machine_mode mode,
802 const_tree type, bool named)
804 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
806 if (!named
807 || fr30_must_pass_in_stack (mode, type)
808 || *cum >= FR30_NUM_ARG_REGS)
809 return NULL_RTX;
810 else
811 return gen_rtx_REG (mode, *cum + FIRST_ARG_REGNUM);
814 /* A C statement (sans semicolon) to update the summarizer variable CUM to
815 advance past an argument in the argument list. The values MODE, TYPE and
816 NAMED describe that argument. Once this is done, the variable CUM is
817 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
819 This macro need not do anything if the argument in question was passed on
820 the stack. The compiler knows how to track the amount of stack space used
821 for arguments without any special help. */
822 static void
823 fr30_function_arg_advance (cumulative_args_t cum, enum machine_mode mode,
824 const_tree type, bool named)
826 *get_cumulative_args (cum) += named * fr30_num_arg_regs (mode, type);
829 /*}}}*/
830 /*{{{ Operand predicates */
832 #ifndef Mmode
833 #define Mmode enum machine_mode
834 #endif
836 /* Returns true iff all the registers in the operands array
837 are in descending or ascending order. */
839 fr30_check_multiple_regs (rtx *operands, int num_operands, int descending)
841 if (descending)
843 unsigned int prev_regno = 0;
845 while (num_operands --)
847 if (GET_CODE (operands [num_operands]) != REG)
848 return 0;
850 if (REGNO (operands [num_operands]) < prev_regno)
851 return 0;
853 prev_regno = REGNO (operands [num_operands]);
856 else
858 unsigned int prev_regno = CONDITION_CODE_REGNUM;
860 while (num_operands --)
862 if (GET_CODE (operands [num_operands]) != REG)
863 return 0;
865 if (REGNO (operands [num_operands]) > prev_regno)
866 return 0;
868 prev_regno = REGNO (operands [num_operands]);
872 return 1;
876 fr30_const_double_is_zero (rtx operand)
878 REAL_VALUE_TYPE d;
880 if (operand == NULL || GET_CODE (operand) != CONST_DOUBLE)
881 return 0;
883 REAL_VALUE_FROM_CONST_DOUBLE (d, operand);
885 return REAL_VALUES_EQUAL (d, dconst0);
888 /*}}}*/
889 /*{{{ Instruction Output Routines */
891 /* Output a double word move.
892 It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
893 On the FR30 we are constrained by the fact that it does not
894 support offsetable addresses, and so we have to load the
895 address of the secnd word into the second destination register
896 before we can use it. */
899 fr30_move_double (rtx * operands)
901 rtx src = operands[1];
902 rtx dest = operands[0];
903 enum rtx_code src_code = GET_CODE (src);
904 enum rtx_code dest_code = GET_CODE (dest);
905 enum machine_mode mode = GET_MODE (dest);
906 rtx val;
908 start_sequence ();
910 if (dest_code == REG)
912 if (src_code == REG)
914 int reverse = (REGNO (dest) == REGNO (src) + 1);
916 /* We normally copy the low-numbered register first. However, if
917 the first register of operand 0 is the same as the second register
918 of operand 1, we must copy in the opposite order. */
919 emit_insn (gen_rtx_SET (VOIDmode,
920 operand_subword (dest, reverse, TRUE, mode),
921 operand_subword (src, reverse, TRUE, mode)));
923 emit_insn (gen_rtx_SET (VOIDmode,
924 operand_subword (dest, !reverse, TRUE, mode),
925 operand_subword (src, !reverse, TRUE, mode)));
927 else if (src_code == MEM)
929 rtx addr = XEXP (src, 0);
930 rtx dest0 = operand_subword (dest, 0, TRUE, mode);
931 rtx dest1 = operand_subword (dest, 1, TRUE, mode);
932 rtx new_mem;
934 gcc_assert (GET_CODE (addr) == REG);
936 /* Copy the address before clobbering it. See PR 34174. */
937 emit_insn (gen_rtx_SET (SImode, dest1, addr));
938 emit_insn (gen_rtx_SET (VOIDmode, dest0,
939 adjust_address (src, SImode, 0)));
940 emit_insn (gen_rtx_SET (SImode, dest1,
941 plus_constant (SImode, dest1,
942 UNITS_PER_WORD)));
944 new_mem = gen_rtx_MEM (SImode, dest1);
945 MEM_COPY_ATTRIBUTES (new_mem, src);
947 emit_insn (gen_rtx_SET (VOIDmode, dest1, new_mem));
949 else if (src_code == CONST_INT || src_code == CONST_DOUBLE)
951 rtx words[2];
952 split_double (src, &words[0], &words[1]);
953 emit_insn (gen_rtx_SET (VOIDmode,
954 operand_subword (dest, 0, TRUE, mode),
955 words[0]));
957 emit_insn (gen_rtx_SET (VOIDmode,
958 operand_subword (dest, 1, TRUE, mode),
959 words[1]));
962 else if (src_code == REG && dest_code == MEM)
964 rtx addr = XEXP (dest, 0);
965 rtx src0;
966 rtx src1;
968 gcc_assert (GET_CODE (addr) == REG);
970 src0 = operand_subword (src, 0, TRUE, mode);
971 src1 = operand_subword (src, 1, TRUE, mode);
973 emit_move_insn (adjust_address (dest, SImode, 0), src0);
975 if (REGNO (addr) == STACK_POINTER_REGNUM
976 || REGNO (addr) == FRAME_POINTER_REGNUM)
977 emit_insn (gen_rtx_SET (VOIDmode,
978 adjust_address (dest, SImode, UNITS_PER_WORD),
979 src1));
980 else
982 rtx new_mem;
983 rtx scratch_reg_r0 = gen_rtx_REG (SImode, 0);
985 /* We need a scratch register to hold the value of 'address + 4'.
986 We use r0 for this purpose. It is used for example for long
987 jumps and is already marked to not be used by normal register
988 allocation. */
989 emit_insn (gen_movsi_internal (scratch_reg_r0, addr));
990 emit_insn (gen_addsi_small_int (scratch_reg_r0, scratch_reg_r0,
991 GEN_INT (UNITS_PER_WORD)));
992 new_mem = gen_rtx_MEM (SImode, scratch_reg_r0);
993 MEM_COPY_ATTRIBUTES (new_mem, dest);
994 emit_move_insn (new_mem, src1);
995 emit_insn (gen_blockage ());
998 else
999 /* This should have been prevented by the constraints on movdi_insn. */
1000 gcc_unreachable ();
1002 val = get_insns ();
1003 end_sequence ();
1005 return val;
1008 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
1010 bool
1011 fr30_frame_pointer_required (void)
1013 return (flag_omit_frame_pointer == 0 || crtl->args.pretend_args_size > 0);
1016 /*}}}*/
1017 /*{{{ Trampoline Output Routines */
1019 /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
1020 On the FR30, the trampoline is:
1023 ldi:32 STATIC, r12
1025 ldi:32 FUNCTION, r0
1026 jmp @r0
1028 The no-ops are to guarantee that the static chain and final
1029 target are 32 bit aligned within the trampoline. That allows us to
1030 initialize those locations with simple SImode stores. The alternative
1031 would be to use HImode stores. */
1033 static void
1034 fr30_asm_trampoline_template (FILE *f)
1036 fprintf (f, "\tnop\n");
1037 fprintf (f, "\tldi:32\t#0, %s\n", reg_names [STATIC_CHAIN_REGNUM]);
1038 fprintf (f, "\tnop\n");
1039 fprintf (f, "\tldi:32\t#0, %s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
1040 fprintf (f, "\tjmp\t@%s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
1043 /* Implement TARGET_TRAMPOLINE_INIT. */
1045 static void
1046 fr30_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
1048 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
1049 rtx mem;
1051 emit_block_move (m_tramp, assemble_trampoline_template (),
1052 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
1054 mem = adjust_address (m_tramp, SImode, 4);
1055 emit_move_insn (mem, chain_value);
1056 mem = adjust_address (m_tramp, SImode, 12);
1057 emit_move_insn (mem, fnaddr);
1060 /*}}}*/
1061 /* Local Variables: */
1062 /* folded-file: t */
1063 /* End: */