Merged revisions 195034,195219,195245,195357,195374,195428,195599,195673,195809 via...
[official-gcc.git] / main / gcc / config / fr30 / fr30.c
blob4a45feafd04760a046d3cf6d1ef752794679eed2
1 /* FR30 specific functions.
2 Copyright (C) 1998-2013 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 "output.h"
37 #include "expr.h"
38 #include "obstack.h"
39 #include "except.h"
40 #include "function.h"
41 #include "df.h"
42 #include "diagnostic-core.h"
43 #include "tm_p.h"
44 #include "target.h"
45 #include "target-def.h"
47 /*}}}*/
48 /*{{{ Function Prologues & Epilogues */
50 /* The FR30 stack looks like this:
52 Before call After call
53 FP ->| | | |
54 +-----------------------+ +-----------------------+ high
55 | | | | memory
56 | local variables, | | local variables, |
57 | reg save area, etc. | | reg save area, etc. |
58 | | | |
59 +-----------------------+ +-----------------------+
60 | | | |
61 | args to the func that | | args to this func. |
62 | is being called that | | |
63 SP ->| do not fit in regs | | |
64 +-----------------------+ +-----------------------+
65 | args that used to be | \
66 | in regs; only created | | pretend_size
67 AP-> | for vararg funcs | /
68 +-----------------------+
69 | | \
70 | register save area | |
71 | | |
72 +-----------------------+ | reg_size
73 | return address | |
74 +-----------------------+ |
75 FP ->| previous frame ptr | /
76 +-----------------------+
77 | | \
78 | local variables | | var_size
79 | | /
80 +-----------------------+
81 | | \
82 low | room for args to | |
83 memory | other funcs called | | args_size
84 | from this one | |
85 SP ->| | /
86 +-----------------------+
88 Note, AP is a fake hard register. It will be eliminated in favor of
89 SP or FP as appropriate.
91 Note, Some or all of the stack sections above may be omitted if they
92 are not needed. */
94 /* Structure to be filled in by fr30_compute_frame_size() with register
95 save masks, and offsets for the current function. */
96 struct fr30_frame_info
98 unsigned int total_size; /* # Bytes that the entire frame takes up. */
99 unsigned int pretend_size; /* # Bytes we push and pretend caller did. */
100 unsigned int args_size; /* # Bytes that outgoing arguments take up. */
101 unsigned int reg_size; /* # Bytes needed to store regs. */
102 unsigned int var_size; /* # Bytes that variables take up. */
103 unsigned int frame_size; /* # Bytes in current frame. */
104 unsigned int gmask; /* Mask of saved registers. */
105 unsigned int save_fp; /* Nonzero if frame pointer must be saved. */
106 unsigned int save_rp; /* Nonzero if return pointer must be saved. */
107 int initialised; /* Nonzero if frame size already calculated. */
110 /* Current frame information calculated by fr30_compute_frame_size(). */
111 static struct fr30_frame_info current_frame_info;
113 /* Zero structure to initialize current_frame_info. */
114 static struct fr30_frame_info zero_frame_info;
116 static void fr30_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
117 tree, int *, int);
118 static bool fr30_must_pass_in_stack (enum machine_mode, const_tree);
119 static int fr30_arg_partial_bytes (cumulative_args_t, enum machine_mode,
120 tree, bool);
121 static rtx fr30_function_arg (cumulative_args_t, enum machine_mode,
122 const_tree, bool);
123 static void fr30_function_arg_advance (cumulative_args_t, enum machine_mode,
124 const_tree, bool);
125 static bool fr30_frame_pointer_required (void);
126 static rtx fr30_function_value (const_tree, const_tree, bool);
127 static rtx fr30_libcall_value (enum machine_mode, const_rtx);
128 static bool fr30_function_value_regno_p (const unsigned int);
129 static bool fr30_can_eliminate (const int, const int);
130 static void fr30_asm_trampoline_template (FILE *);
131 static void fr30_trampoline_init (rtx, tree, rtx);
132 static int fr30_num_arg_regs (enum machine_mode, const_tree);
134 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
135 #define RETURN_POINTER_MASK (1 << (RETURN_POINTER_REGNUM))
137 /* Tell prologue and epilogue if register REGNO should be saved / restored.
138 The return address and frame pointer are treated separately.
139 Don't consider them here. */
140 #define MUST_SAVE_REGISTER(regno) \
141 ( (regno) != RETURN_POINTER_REGNUM \
142 && (regno) != FRAME_POINTER_REGNUM \
143 && df_regs_ever_live_p (regno) \
144 && ! call_used_regs [regno] )
146 #define MUST_SAVE_FRAME_POINTER (df_regs_ever_live_p (FRAME_POINTER_REGNUM) || frame_pointer_needed)
147 #define MUST_SAVE_RETURN_POINTER (df_regs_ever_live_p (RETURN_POINTER_REGNUM) || crtl->profile)
149 #if UNITS_PER_WORD == 4
150 #define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
151 #endif
153 /* Initialize the GCC target structure. */
154 #undef TARGET_ASM_ALIGNED_HI_OP
155 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
156 #undef TARGET_ASM_ALIGNED_SI_OP
157 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
159 #undef TARGET_PROMOTE_PROTOTYPES
160 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
161 #undef TARGET_PASS_BY_REFERENCE
162 #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
163 #undef TARGET_ARG_PARTIAL_BYTES
164 #define TARGET_ARG_PARTIAL_BYTES fr30_arg_partial_bytes
165 #undef TARGET_FUNCTION_ARG
166 #define TARGET_FUNCTION_ARG fr30_function_arg
167 #undef TARGET_FUNCTION_ARG_ADVANCE
168 #define TARGET_FUNCTION_ARG_ADVANCE fr30_function_arg_advance
170 #undef TARGET_FUNCTION_VALUE
171 #define TARGET_FUNCTION_VALUE fr30_function_value
172 #undef TARGET_LIBCALL_VALUE
173 #define TARGET_LIBCALL_VALUE fr30_libcall_value
174 #undef TARGET_FUNCTION_VALUE_REGNO_P
175 #define TARGET_FUNCTION_VALUE_REGNO_P fr30_function_value_regno_p
177 #undef TARGET_SETUP_INCOMING_VARARGS
178 #define TARGET_SETUP_INCOMING_VARARGS fr30_setup_incoming_varargs
179 #undef TARGET_MUST_PASS_IN_STACK
180 #define TARGET_MUST_PASS_IN_STACK fr30_must_pass_in_stack
182 #undef TARGET_FRAME_POINTER_REQUIRED
183 #define TARGET_FRAME_POINTER_REQUIRED fr30_frame_pointer_required
185 #undef TARGET_CAN_ELIMINATE
186 #define TARGET_CAN_ELIMINATE fr30_can_eliminate
188 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
189 #define TARGET_ASM_TRAMPOLINE_TEMPLATE fr30_asm_trampoline_template
190 #undef TARGET_TRAMPOLINE_INIT
191 #define TARGET_TRAMPOLINE_INIT fr30_trampoline_init
193 struct gcc_target targetm = TARGET_INITIALIZER;
196 /* Worker function for TARGET_CAN_ELIMINATE. */
198 bool
199 fr30_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
201 return (to == FRAME_POINTER_REGNUM || ! frame_pointer_needed);
204 /* Returns the number of bytes offset between FROM_REG and TO_REG
205 for the current function. As a side effect it fills in the
206 current_frame_info structure, if the data is available. */
207 unsigned int
208 fr30_compute_frame_size (int from_reg, int to_reg)
210 int regno;
211 unsigned int return_value;
212 unsigned int var_size;
213 unsigned int args_size;
214 unsigned int pretend_size;
215 unsigned int reg_size;
216 unsigned int gmask;
218 var_size = WORD_ALIGN (get_frame_size ());
219 args_size = WORD_ALIGN (crtl->outgoing_args_size);
220 pretend_size = crtl->args.pretend_args_size;
222 reg_size = 0;
223 gmask = 0;
225 /* Calculate space needed for registers. */
226 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++)
228 if (MUST_SAVE_REGISTER (regno))
230 reg_size += UNITS_PER_WORD;
231 gmask |= 1 << regno;
235 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
236 current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER;
238 reg_size += (current_frame_info.save_fp + current_frame_info.save_rp)
239 * UNITS_PER_WORD;
241 /* Save computed information. */
242 current_frame_info.pretend_size = pretend_size;
243 current_frame_info.var_size = var_size;
244 current_frame_info.args_size = args_size;
245 current_frame_info.reg_size = reg_size;
246 current_frame_info.frame_size = args_size + var_size;
247 current_frame_info.total_size = args_size + var_size + reg_size + pretend_size;
248 current_frame_info.gmask = gmask;
249 current_frame_info.initialised = reload_completed;
251 /* Calculate the required distance. */
252 return_value = 0;
254 if (to_reg == STACK_POINTER_REGNUM)
255 return_value += args_size + var_size;
257 if (from_reg == ARG_POINTER_REGNUM)
258 return_value += reg_size;
260 return return_value;
263 /* Called after register allocation to add any instructions needed for the
264 prologue. Using a prologue insn is favored compared to putting all of the
265 instructions in output_function_prologue(), since it allows the scheduler
266 to intermix instructions with the saves of the caller saved registers. In
267 some cases, it might be necessary to emit a barrier instruction as the last
268 insn to prevent such scheduling. */
270 void
271 fr30_expand_prologue (void)
273 int regno;
274 rtx insn;
276 if (! current_frame_info.initialised)
277 fr30_compute_frame_size (0, 0);
279 /* This cases shouldn't happen. Catch it now. */
280 gcc_assert (current_frame_info.total_size || !current_frame_info.gmask);
282 /* Allocate space for register arguments if this is a variadic function. */
283 if (current_frame_info.pretend_size)
285 int regs_to_save = current_frame_info.pretend_size / UNITS_PER_WORD;
287 /* Push argument registers into the pretend arg area. */
288 for (regno = FIRST_ARG_REGNUM + FR30_NUM_ARG_REGS; regno --, regs_to_save --;)
290 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
291 RTX_FRAME_RELATED_P (insn) = 1;
295 if (current_frame_info.gmask)
297 /* Save any needed call-saved regs. */
298 for (regno = STACK_POINTER_REGNUM; regno--;)
300 if ((current_frame_info.gmask & (1 << regno)) != 0)
302 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
303 RTX_FRAME_RELATED_P (insn) = 1;
308 /* Save return address if necessary. */
309 if (current_frame_info.save_rp)
311 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode,
312 RETURN_POINTER_REGNUM)));
313 RTX_FRAME_RELATED_P (insn) = 1;
316 /* Save old frame pointer and create new one, if necessary. */
317 if (current_frame_info.save_fp)
319 if (current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
321 int enter_size = current_frame_info.frame_size + UNITS_PER_WORD;
322 rtx pattern;
324 insn = emit_insn (gen_enter_func (GEN_INT (enter_size)));
325 RTX_FRAME_RELATED_P (insn) = 1;
327 pattern = PATTERN (insn);
329 /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
330 if (GET_CODE (pattern) == PARALLEL)
332 int x;
333 for (x = XVECLEN (pattern, 0); x--;)
335 rtx part = XVECEXP (pattern, 0, x);
337 /* One of the insns in the ENTER pattern updates the
338 frame pointer. If we do not actually need the frame
339 pointer in this function then this is a side effect
340 rather than a desired effect, so we do not mark that
341 insn as being related to the frame set up. Doing this
342 allows us to compile the crash66.C test file in the
343 G++ testsuite. */
344 if (! frame_pointer_needed
345 && GET_CODE (part) == SET
346 && SET_DEST (part) == hard_frame_pointer_rtx)
347 RTX_FRAME_RELATED_P (part) = 0;
348 else
349 RTX_FRAME_RELATED_P (part) = 1;
353 else
355 insn = emit_insn (gen_movsi_push (frame_pointer_rtx));
356 RTX_FRAME_RELATED_P (insn) = 1;
358 if (frame_pointer_needed)
360 insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
361 RTX_FRAME_RELATED_P (insn) = 1;
366 /* Allocate the stack frame. */
367 if (current_frame_info.frame_size == 0)
368 ; /* Nothing to do. */
369 else if (current_frame_info.save_fp
370 && current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
371 ; /* Nothing to do. */
372 else if (current_frame_info.frame_size <= 512)
374 insn = emit_insn (gen_add_to_stack
375 (GEN_INT (- (signed) current_frame_info.frame_size)));
376 RTX_FRAME_RELATED_P (insn) = 1;
378 else
380 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
381 insn = emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
382 RTX_FRAME_RELATED_P (insn) = 1;
383 insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
384 RTX_FRAME_RELATED_P (insn) = 1;
387 if (crtl->profile)
388 emit_insn (gen_blockage ());
391 /* Called after register allocation to add any instructions needed for the
392 epilogue. Using an epilogue insn is favored compared to putting all of the
393 instructions in output_function_epilogue(), since it allows the scheduler
394 to intermix instructions with the restores of the caller saved registers.
395 In some cases, it might be necessary to emit a barrier instruction as the
396 first insn to prevent such scheduling. */
397 void
398 fr30_expand_epilogue (void)
400 int regno;
402 /* Perform the inversion operations of the prologue. */
403 gcc_assert (current_frame_info.initialised);
405 /* Pop local variables and arguments off the stack.
406 If frame_pointer_needed is TRUE then the frame pointer register
407 has actually been used as a frame pointer, and we can recover
408 the stack pointer from it, otherwise we must unwind the stack
409 manually. */
410 if (current_frame_info.frame_size > 0)
412 if (current_frame_info.save_fp && frame_pointer_needed)
414 emit_insn (gen_leave_func ());
415 current_frame_info.save_fp = 0;
417 else if (current_frame_info.frame_size <= 508)
418 emit_insn (gen_add_to_stack
419 (GEN_INT (current_frame_info.frame_size)));
420 else
422 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
423 emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
424 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
428 if (current_frame_info.save_fp)
429 emit_insn (gen_movsi_pop (frame_pointer_rtx));
431 /* Pop all the registers that were pushed. */
432 if (current_frame_info.save_rp)
433 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, RETURN_POINTER_REGNUM)));
435 for (regno = 0; regno < STACK_POINTER_REGNUM; regno ++)
436 if (current_frame_info.gmask & (1 << regno))
437 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno)));
439 if (current_frame_info.pretend_size)
440 emit_insn (gen_add_to_stack (GEN_INT (current_frame_info.pretend_size)));
442 /* Reset state info for each function. */
443 current_frame_info = zero_frame_info;
445 emit_jump_insn (gen_return_from_func ());
448 /* Do any needed setup for a variadic function. We must create a register
449 parameter block, and then copy any anonymous arguments, plus the last
450 named argument, from registers into memory. * copying actually done in
451 fr30_expand_prologue().
453 ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
454 which has type TYPE and mode MODE, and we rely on this fact. */
455 void
456 fr30_setup_incoming_varargs (cumulative_args_t arg_regs_used_so_far_v,
457 enum machine_mode mode,
458 tree type ATTRIBUTE_UNUSED,
459 int *pretend_size,
460 int second_time ATTRIBUTE_UNUSED)
462 CUMULATIVE_ARGS *arg_regs_used_so_far
463 = get_cumulative_args (arg_regs_used_so_far_v);
464 int size;
466 /* All BLKmode values are passed by reference. */
467 gcc_assert (mode != BLKmode);
469 /* ??? This run-time test as well as the code inside the if
470 statement is probably unnecessary. */
471 if (targetm.calls.strict_argument_naming (arg_regs_used_so_far_v))
472 /* If TARGET_STRICT_ARGUMENT_NAMING returns true, then the last named
473 arg must not be treated as an anonymous arg. */
474 /* ??? This is a pointer increment, which makes no sense. */
475 arg_regs_used_so_far += fr30_num_arg_regs (mode, type);
477 size = FR30_NUM_ARG_REGS - (* arg_regs_used_so_far);
479 if (size <= 0)
480 return;
482 * pretend_size = (size * UNITS_PER_WORD);
485 /*}}}*/
486 /*{{{ Printing operands */
488 /* Print a memory address as an operand to reference that memory location. */
490 void
491 fr30_print_operand_address (FILE *stream, rtx address)
493 switch (GET_CODE (address))
495 case SYMBOL_REF:
496 output_addr_const (stream, address);
497 break;
499 default:
500 fprintf (stderr, "code = %x\n", GET_CODE (address));
501 debug_rtx (address);
502 output_operand_lossage ("fr30_print_operand_address: unhandled address");
503 break;
507 /* Print an operand. */
509 void
510 fr30_print_operand (FILE *file, rtx x, int code)
512 rtx x0;
514 switch (code)
516 case '#':
517 /* Output a :D if this instruction is delayed. */
518 if (dbr_sequence_length () != 0)
519 fputs (":D", file);
520 return;
522 case 'p':
523 /* Compute the register name of the second register in a hi/lo
524 register pair. */
525 if (GET_CODE (x) != REG)
526 output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
527 else
528 fprintf (file, "r%d", REGNO (x) + 1);
529 return;
531 case 'b':
532 /* Convert GCC's comparison operators into FR30 comparison codes. */
533 switch (GET_CODE (x))
535 case EQ: fprintf (file, "eq"); break;
536 case NE: fprintf (file, "ne"); break;
537 case LT: fprintf (file, "lt"); break;
538 case LE: fprintf (file, "le"); break;
539 case GT: fprintf (file, "gt"); break;
540 case GE: fprintf (file, "ge"); break;
541 case LTU: fprintf (file, "c"); break;
542 case LEU: fprintf (file, "ls"); break;
543 case GTU: fprintf (file, "hi"); break;
544 case GEU: fprintf (file, "nc"); break;
545 default:
546 output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
547 break;
549 return;
551 case 'B':
552 /* Convert GCC's comparison operators into the complimentary FR30
553 comparison codes. */
554 switch (GET_CODE (x))
556 case EQ: fprintf (file, "ne"); break;
557 case NE: fprintf (file, "eq"); break;
558 case LT: fprintf (file, "ge"); break;
559 case LE: fprintf (file, "gt"); break;
560 case GT: fprintf (file, "le"); break;
561 case GE: fprintf (file, "lt"); break;
562 case LTU: fprintf (file, "nc"); break;
563 case LEU: fprintf (file, "hi"); break;
564 case GTU: fprintf (file, "ls"); break;
565 case GEU: fprintf (file, "c"); break;
566 default:
567 output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
568 break;
570 return;
572 case 'A':
573 /* Print a signed byte value as an unsigned value. */
574 if (GET_CODE (x) != CONST_INT)
575 output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
576 else
578 HOST_WIDE_INT val;
580 val = INTVAL (x);
582 val &= 0xff;
584 fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
586 return;
588 case 'x':
589 if (GET_CODE (x) != CONST_INT
590 || INTVAL (x) < 16
591 || INTVAL (x) > 32)
592 output_operand_lossage ("fr30_print_operand: invalid %%x code");
593 else
594 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) - 16);
595 return;
597 case 'F':
598 if (GET_CODE (x) != CONST_DOUBLE)
599 output_operand_lossage ("fr30_print_operand: invalid %%F code");
600 else
602 char str[30];
604 real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x),
605 sizeof (str), 0, 1);
606 fputs (str, file);
608 return;
610 case 0:
611 /* Handled below. */
612 break;
614 default:
615 fprintf (stderr, "unknown code = %x\n", code);
616 output_operand_lossage ("fr30_print_operand: unknown code");
617 return;
620 switch (GET_CODE (x))
622 case REG:
623 fputs (reg_names [REGNO (x)], file);
624 break;
626 case MEM:
627 x0 = XEXP (x,0);
629 switch (GET_CODE (x0))
631 case REG:
632 gcc_assert ((unsigned) REGNO (x0) < ARRAY_SIZE (reg_names));
633 fprintf (file, "@%s", reg_names [REGNO (x0)]);
634 break;
636 case PLUS:
637 if (GET_CODE (XEXP (x0, 0)) != REG
638 || REGNO (XEXP (x0, 0)) < FRAME_POINTER_REGNUM
639 || REGNO (XEXP (x0, 0)) > STACK_POINTER_REGNUM
640 || GET_CODE (XEXP (x0, 1)) != CONST_INT)
642 fprintf (stderr, "bad INDEXed address:");
643 debug_rtx (x);
644 output_operand_lossage ("fr30_print_operand: unhandled MEM");
646 else if (REGNO (XEXP (x0, 0)) == FRAME_POINTER_REGNUM)
648 HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
649 if (val < -(1 << 9) || val > ((1 << 9) - 4))
651 fprintf (stderr, "frame INDEX out of range:");
652 debug_rtx (x);
653 output_operand_lossage ("fr30_print_operand: unhandled MEM");
655 fprintf (file, "@(r14, #" HOST_WIDE_INT_PRINT_DEC ")", val);
657 else
659 HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
660 if (val < 0 || val > ((1 << 6) - 4))
662 fprintf (stderr, "stack INDEX out of range:");
663 debug_rtx (x);
664 output_operand_lossage ("fr30_print_operand: unhandled MEM");
666 fprintf (file, "@(r15, #" HOST_WIDE_INT_PRINT_DEC ")", val);
668 break;
670 case SYMBOL_REF:
671 output_address (x0);
672 break;
674 default:
675 fprintf (stderr, "bad MEM code = %x\n", GET_CODE (x0));
676 debug_rtx (x);
677 output_operand_lossage ("fr30_print_operand: unhandled MEM");
678 break;
680 break;
682 case CONST_DOUBLE :
683 /* We handle SFmode constants here as output_addr_const doesn't. */
684 if (GET_MODE (x) == SFmode)
686 REAL_VALUE_TYPE d;
687 long l;
689 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
690 REAL_VALUE_TO_TARGET_SINGLE (d, l);
691 fprintf (file, "0x%08lx", l);
692 break;
695 /* Fall through. Let output_addr_const deal with it. */
696 default:
697 output_addr_const (file, x);
698 break;
701 return;
704 /*}}}*/
706 /* Implements TARGET_FUNCTION_VALUE. */
708 static rtx
709 fr30_function_value (const_tree valtype,
710 const_tree fntype_or_decli ATTRIBUTE_UNUSED,
711 bool outgoing ATTRIBUTE_UNUSED)
713 return gen_rtx_REG (TYPE_MODE (valtype), RETURN_VALUE_REGNUM);
716 /* Implements TARGET_LIBCALL_VALUE. */
718 static rtx
719 fr30_libcall_value (enum machine_mode mode,
720 const_rtx fun ATTRIBUTE_UNUSED)
722 return gen_rtx_REG (mode, RETURN_VALUE_REGNUM);
725 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
727 static bool
728 fr30_function_value_regno_p (const unsigned int regno)
730 return (regno == RETURN_VALUE_REGNUM);
733 /*{{{ Function arguments */
735 /* Return true if we should pass an argument on the stack rather than
736 in registers. */
738 static bool
739 fr30_must_pass_in_stack (enum machine_mode mode, const_tree type)
741 if (mode == BLKmode)
742 return true;
743 if (type == NULL)
744 return false;
745 return AGGREGATE_TYPE_P (type);
748 /* Compute the number of word sized registers needed to hold a
749 function argument of mode INT_MODE and tree type TYPE. */
750 static int
751 fr30_num_arg_regs (enum machine_mode mode, const_tree type)
753 int size;
755 if (targetm.calls.must_pass_in_stack (mode, type))
756 return 0;
758 if (type && mode == BLKmode)
759 size = int_size_in_bytes (type);
760 else
761 size = GET_MODE_SIZE (mode);
763 return (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
766 /* Returns the number of bytes in which *part* of a parameter of machine
767 mode MODE and tree type TYPE (which may be NULL if the type is not known).
768 If the argument fits entirely in the argument registers, or entirely on
769 the stack, then 0 is returned.
770 CUM is the number of argument registers already used by earlier
771 parameters to the function. */
773 static int
774 fr30_arg_partial_bytes (cumulative_args_t cum_v, enum machine_mode mode,
775 tree type, bool named)
777 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
779 /* Unnamed arguments, i.e. those that are prototyped as ...
780 are always passed on the stack.
781 Also check here to see if all the argument registers are full. */
782 if (named == 0 || *cum >= FR30_NUM_ARG_REGS)
783 return 0;
785 /* Work out how many argument registers would be needed if this
786 parameter were to be passed entirely in registers. If there
787 are sufficient argument registers available (or if no registers
788 are needed because the parameter must be passed on the stack)
789 then return zero, as this parameter does not require partial
790 register, partial stack stack space. */
791 if (*cum + fr30_num_arg_regs (mode, type) <= FR30_NUM_ARG_REGS)
792 return 0;
794 return (FR30_NUM_ARG_REGS - *cum) * UNITS_PER_WORD;
797 static rtx
798 fr30_function_arg (cumulative_args_t cum_v, enum machine_mode mode,
799 const_tree type, bool named)
801 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
803 if (!named
804 || fr30_must_pass_in_stack (mode, type)
805 || *cum >= FR30_NUM_ARG_REGS)
806 return NULL_RTX;
807 else
808 return gen_rtx_REG (mode, *cum + FIRST_ARG_REGNUM);
811 /* A C statement (sans semicolon) to update the summarizer variable CUM to
812 advance past an argument in the argument list. The values MODE, TYPE and
813 NAMED describe that argument. Once this is done, the variable CUM is
814 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
816 This macro need not do anything if the argument in question was passed on
817 the stack. The compiler knows how to track the amount of stack space used
818 for arguments without any special help. */
819 static void
820 fr30_function_arg_advance (cumulative_args_t cum, enum machine_mode mode,
821 const_tree type, bool named)
823 *get_cumulative_args (cum) += named * fr30_num_arg_regs (mode, type);
826 /*}}}*/
827 /*{{{ Operand predicates */
829 #ifndef Mmode
830 #define Mmode enum machine_mode
831 #endif
833 /* Returns true iff all the registers in the operands array
834 are in descending or ascending order. */
836 fr30_check_multiple_regs (rtx *operands, int num_operands, int descending)
838 if (descending)
840 unsigned int prev_regno = 0;
842 while (num_operands --)
844 if (GET_CODE (operands [num_operands]) != REG)
845 return 0;
847 if (REGNO (operands [num_operands]) < prev_regno)
848 return 0;
850 prev_regno = REGNO (operands [num_operands]);
853 else
855 unsigned int prev_regno = CONDITION_CODE_REGNUM;
857 while (num_operands --)
859 if (GET_CODE (operands [num_operands]) != REG)
860 return 0;
862 if (REGNO (operands [num_operands]) > prev_regno)
863 return 0;
865 prev_regno = REGNO (operands [num_operands]);
869 return 1;
873 fr30_const_double_is_zero (rtx operand)
875 REAL_VALUE_TYPE d;
877 if (operand == NULL || GET_CODE (operand) != CONST_DOUBLE)
878 return 0;
880 REAL_VALUE_FROM_CONST_DOUBLE (d, operand);
882 return REAL_VALUES_EQUAL (d, dconst0);
885 /*}}}*/
886 /*{{{ Instruction Output Routines */
888 /* Output a double word move.
889 It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
890 On the FR30 we are constrained by the fact that it does not
891 support offsetable addresses, and so we have to load the
892 address of the secnd word into the second destination register
893 before we can use it. */
896 fr30_move_double (rtx * operands)
898 rtx src = operands[1];
899 rtx dest = operands[0];
900 enum rtx_code src_code = GET_CODE (src);
901 enum rtx_code dest_code = GET_CODE (dest);
902 enum machine_mode mode = GET_MODE (dest);
903 rtx val;
905 start_sequence ();
907 if (dest_code == REG)
909 if (src_code == REG)
911 int reverse = (REGNO (dest) == REGNO (src) + 1);
913 /* We normally copy the low-numbered register first. However, if
914 the first register of operand 0 is the same as the second register
915 of operand 1, we must copy in the opposite order. */
916 emit_insn (gen_rtx_SET (VOIDmode,
917 operand_subword (dest, reverse, TRUE, mode),
918 operand_subword (src, reverse, TRUE, mode)));
920 emit_insn (gen_rtx_SET (VOIDmode,
921 operand_subword (dest, !reverse, TRUE, mode),
922 operand_subword (src, !reverse, TRUE, mode)));
924 else if (src_code == MEM)
926 rtx addr = XEXP (src, 0);
927 rtx dest0 = operand_subword (dest, 0, TRUE, mode);
928 rtx dest1 = operand_subword (dest, 1, TRUE, mode);
929 rtx new_mem;
931 gcc_assert (GET_CODE (addr) == REG);
933 /* Copy the address before clobbering it. See PR 34174. */
934 emit_insn (gen_rtx_SET (SImode, dest1, addr));
935 emit_insn (gen_rtx_SET (VOIDmode, dest0,
936 adjust_address (src, SImode, 0)));
937 emit_insn (gen_rtx_SET (SImode, dest1,
938 plus_constant (SImode, dest1,
939 UNITS_PER_WORD)));
941 new_mem = gen_rtx_MEM (SImode, dest1);
942 MEM_COPY_ATTRIBUTES (new_mem, src);
944 emit_insn (gen_rtx_SET (VOIDmode, dest1, new_mem));
946 else if (src_code == CONST_INT || src_code == CONST_DOUBLE)
948 rtx words[2];
949 split_double (src, &words[0], &words[1]);
950 emit_insn (gen_rtx_SET (VOIDmode,
951 operand_subword (dest, 0, TRUE, mode),
952 words[0]));
954 emit_insn (gen_rtx_SET (VOIDmode,
955 operand_subword (dest, 1, TRUE, mode),
956 words[1]));
959 else if (src_code == REG && dest_code == MEM)
961 rtx addr = XEXP (dest, 0);
962 rtx src0;
963 rtx src1;
965 gcc_assert (GET_CODE (addr) == REG);
967 src0 = operand_subword (src, 0, TRUE, mode);
968 src1 = operand_subword (src, 1, TRUE, mode);
970 emit_move_insn (adjust_address (dest, SImode, 0), src0);
972 if (REGNO (addr) == STACK_POINTER_REGNUM
973 || REGNO (addr) == FRAME_POINTER_REGNUM)
974 emit_insn (gen_rtx_SET (VOIDmode,
975 adjust_address (dest, SImode, UNITS_PER_WORD),
976 src1));
977 else
979 rtx new_mem;
980 rtx scratch_reg_r0 = gen_rtx_REG (SImode, 0);
982 /* We need a scratch register to hold the value of 'address + 4'.
983 We use r0 for this purpose. It is used for example for long
984 jumps and is already marked to not be used by normal register
985 allocation. */
986 emit_insn (gen_movsi_internal (scratch_reg_r0, addr));
987 emit_insn (gen_addsi_small_int (scratch_reg_r0, scratch_reg_r0,
988 GEN_INT (UNITS_PER_WORD)));
989 new_mem = gen_rtx_MEM (SImode, scratch_reg_r0);
990 MEM_COPY_ATTRIBUTES (new_mem, dest);
991 emit_move_insn (new_mem, src1);
992 emit_insn (gen_blockage ());
995 else
996 /* This should have been prevented by the constraints on movdi_insn. */
997 gcc_unreachable ();
999 val = get_insns ();
1000 end_sequence ();
1002 return val;
1005 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
1007 bool
1008 fr30_frame_pointer_required (void)
1010 return (flag_omit_frame_pointer == 0 || crtl->args.pretend_args_size > 0);
1013 /*}}}*/
1014 /*{{{ Trampoline Output Routines */
1016 /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
1017 On the FR30, the trampoline is:
1020 ldi:32 STATIC, r12
1022 ldi:32 FUNCTION, r0
1023 jmp @r0
1025 The no-ops are to guarantee that the static chain and final
1026 target are 32 bit aligned within the trampoline. That allows us to
1027 initialize those locations with simple SImode stores. The alternative
1028 would be to use HImode stores. */
1030 static void
1031 fr30_asm_trampoline_template (FILE *f)
1033 fprintf (f, "\tnop\n");
1034 fprintf (f, "\tldi:32\t#0, %s\n", reg_names [STATIC_CHAIN_REGNUM]);
1035 fprintf (f, "\tnop\n");
1036 fprintf (f, "\tldi:32\t#0, %s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
1037 fprintf (f, "\tjmp\t@%s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
1040 /* Implement TARGET_TRAMPOLINE_INIT. */
1042 static void
1043 fr30_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
1045 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
1046 rtx mem;
1048 emit_block_move (m_tramp, assemble_trampoline_template (),
1049 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
1051 mem = adjust_address (m_tramp, SImode, 4);
1052 emit_move_insn (mem, chain_value);
1053 mem = adjust_address (m_tramp, SImode, 12);
1054 emit_move_insn (mem, fnaddr);
1057 /*}}}*/
1058 /* Local Variables: */
1059 /* folded-file: t */
1060 /* End: */