PR c/79855: add full stop to store merging param descriptions
[official-gcc.git] / gcc / config / fr30 / fr30.c
blob42bec9f733c2bb8197cfeb8e5c603af2575f5367
1 /* FR30 specific functions.
2 Copyright (C) 1998-2017 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 "backend.h"
27 #include "target.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "df.h"
31 #include "memmodel.h"
32 #include "emit-rtl.h"
33 #include "stor-layout.h"
34 #include "varasm.h"
35 #include "output.h"
36 #include "expr.h"
37 #include "builtins.h"
39 /* This file should be included last. */
40 #include "target-def.h"
42 /*}}}*/
43 /*{{{ Function Prologues & Epilogues */
45 /* The FR30 stack looks like this:
47 Before call After call
48 FP ->| | | |
49 +-----------------------+ +-----------------------+ high
50 | | | | memory
51 | local variables, | | local variables, |
52 | reg save area, etc. | | reg save area, etc. |
53 | | | |
54 +-----------------------+ +-----------------------+
55 | | | |
56 | args to the func that | | args to this func. |
57 | is being called that | | |
58 SP ->| do not fit in regs | | |
59 +-----------------------+ +-----------------------+
60 | args that used to be | \
61 | in regs; only created | | pretend_size
62 AP-> | for vararg funcs | /
63 +-----------------------+
64 | | \
65 | register save area | |
66 | | |
67 +-----------------------+ | reg_size
68 | return address | |
69 +-----------------------+ |
70 FP ->| previous frame ptr | /
71 +-----------------------+
72 | | \
73 | local variables | | var_size
74 | | /
75 +-----------------------+
76 | | \
77 low | room for args to | |
78 memory | other funcs called | | args_size
79 | from this one | |
80 SP ->| | /
81 +-----------------------+
83 Note, AP is a fake hard register. It will be eliminated in favor of
84 SP or FP as appropriate.
86 Note, Some or all of the stack sections above may be omitted if they
87 are not needed. */
89 /* Structure to be filled in by fr30_compute_frame_size() with register
90 save masks, and offsets for the current function. */
91 struct fr30_frame_info
93 unsigned int total_size; /* # Bytes that the entire frame takes up. */
94 unsigned int pretend_size; /* # Bytes we push and pretend caller did. */
95 unsigned int args_size; /* # Bytes that outgoing arguments take up. */
96 unsigned int reg_size; /* # Bytes needed to store regs. */
97 unsigned int var_size; /* # Bytes that variables take up. */
98 unsigned int frame_size; /* # Bytes in current frame. */
99 unsigned int gmask; /* Mask of saved registers. */
100 unsigned int save_fp; /* Nonzero if frame pointer must be saved. */
101 unsigned int save_rp; /* Nonzero if return pointer must be saved. */
102 int initialised; /* Nonzero if frame size already calculated. */
105 /* Current frame information calculated by fr30_compute_frame_size(). */
106 static struct fr30_frame_info current_frame_info;
108 /* Zero structure to initialize current_frame_info. */
109 static struct fr30_frame_info zero_frame_info;
111 static void fr30_setup_incoming_varargs (cumulative_args_t, machine_mode,
112 tree, int *, int);
113 static bool fr30_must_pass_in_stack (machine_mode, const_tree);
114 static int fr30_arg_partial_bytes (cumulative_args_t, machine_mode,
115 tree, bool);
116 static rtx fr30_function_arg (cumulative_args_t, machine_mode,
117 const_tree, bool);
118 static void fr30_function_arg_advance (cumulative_args_t, machine_mode,
119 const_tree, bool);
120 static bool fr30_frame_pointer_required (void);
121 static rtx fr30_function_value (const_tree, const_tree, bool);
122 static rtx fr30_libcall_value (machine_mode, const_rtx);
123 static bool fr30_function_value_regno_p (const unsigned int);
124 static bool fr30_can_eliminate (const int, const int);
125 static void fr30_asm_trampoline_template (FILE *);
126 static void fr30_trampoline_init (rtx, tree, rtx);
127 static int fr30_num_arg_regs (machine_mode, const_tree);
129 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
130 #define RETURN_POINTER_MASK (1 << (RETURN_POINTER_REGNUM))
132 /* Tell prologue and epilogue if register REGNO should be saved / restored.
133 The return address and frame pointer are treated separately.
134 Don't consider them here. */
135 #define MUST_SAVE_REGISTER(regno) \
136 ( (regno) != RETURN_POINTER_REGNUM \
137 && (regno) != FRAME_POINTER_REGNUM \
138 && df_regs_ever_live_p (regno) \
139 && ! call_used_regs [regno] )
141 #define MUST_SAVE_FRAME_POINTER (df_regs_ever_live_p (FRAME_POINTER_REGNUM) || frame_pointer_needed)
142 #define MUST_SAVE_RETURN_POINTER (df_regs_ever_live_p (RETURN_POINTER_REGNUM) || crtl->profile)
144 #if UNITS_PER_WORD == 4
145 #define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
146 #endif
148 /* Initialize the GCC target structure. */
149 #undef TARGET_ASM_ALIGNED_HI_OP
150 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
151 #undef TARGET_ASM_ALIGNED_SI_OP
152 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
154 #undef TARGET_PROMOTE_PROTOTYPES
155 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
156 #undef TARGET_PASS_BY_REFERENCE
157 #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
158 #undef TARGET_ARG_PARTIAL_BYTES
159 #define TARGET_ARG_PARTIAL_BYTES fr30_arg_partial_bytes
160 #undef TARGET_FUNCTION_ARG
161 #define TARGET_FUNCTION_ARG fr30_function_arg
162 #undef TARGET_FUNCTION_ARG_ADVANCE
163 #define TARGET_FUNCTION_ARG_ADVANCE fr30_function_arg_advance
165 #undef TARGET_FUNCTION_VALUE
166 #define TARGET_FUNCTION_VALUE fr30_function_value
167 #undef TARGET_LIBCALL_VALUE
168 #define TARGET_LIBCALL_VALUE fr30_libcall_value
169 #undef TARGET_FUNCTION_VALUE_REGNO_P
170 #define TARGET_FUNCTION_VALUE_REGNO_P fr30_function_value_regno_p
172 #undef TARGET_SETUP_INCOMING_VARARGS
173 #define TARGET_SETUP_INCOMING_VARARGS fr30_setup_incoming_varargs
174 #undef TARGET_MUST_PASS_IN_STACK
175 #define TARGET_MUST_PASS_IN_STACK fr30_must_pass_in_stack
177 #undef TARGET_FRAME_POINTER_REQUIRED
178 #define TARGET_FRAME_POINTER_REQUIRED fr30_frame_pointer_required
180 #undef TARGET_CAN_ELIMINATE
181 #define TARGET_CAN_ELIMINATE fr30_can_eliminate
183 #undef TARGET_LRA_P
184 #define TARGET_LRA_P hook_bool_void_false
186 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
187 #define TARGET_ASM_TRAMPOLINE_TEMPLATE fr30_asm_trampoline_template
188 #undef TARGET_TRAMPOLINE_INIT
189 #define TARGET_TRAMPOLINE_INIT fr30_trampoline_init
191 struct gcc_target targetm = TARGET_INITIALIZER;
194 /* Worker function for TARGET_CAN_ELIMINATE. */
196 bool
197 fr30_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
199 return (to == FRAME_POINTER_REGNUM || ! frame_pointer_needed);
202 /* Returns the number of bytes offset between FROM_REG and TO_REG
203 for the current function. As a side effect it fills in the
204 current_frame_info structure, if the data is available. */
205 unsigned int
206 fr30_compute_frame_size (int from_reg, int to_reg)
208 int regno;
209 unsigned int return_value;
210 unsigned int var_size;
211 unsigned int args_size;
212 unsigned int pretend_size;
213 unsigned int reg_size;
214 unsigned int gmask;
216 var_size = WORD_ALIGN (get_frame_size ());
217 args_size = WORD_ALIGN (crtl->outgoing_args_size);
218 pretend_size = crtl->args.pretend_args_size;
220 reg_size = 0;
221 gmask = 0;
223 /* Calculate space needed for registers. */
224 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++)
226 if (MUST_SAVE_REGISTER (regno))
228 reg_size += UNITS_PER_WORD;
229 gmask |= 1 << regno;
233 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
234 current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER;
236 reg_size += (current_frame_info.save_fp + current_frame_info.save_rp)
237 * UNITS_PER_WORD;
239 /* Save computed information. */
240 current_frame_info.pretend_size = pretend_size;
241 current_frame_info.var_size = var_size;
242 current_frame_info.args_size = args_size;
243 current_frame_info.reg_size = reg_size;
244 current_frame_info.frame_size = args_size + var_size;
245 current_frame_info.total_size = args_size + var_size + reg_size + pretend_size;
246 current_frame_info.gmask = gmask;
247 current_frame_info.initialised = reload_completed;
249 /* Calculate the required distance. */
250 return_value = 0;
252 if (to_reg == STACK_POINTER_REGNUM)
253 return_value += args_size + var_size;
255 if (from_reg == ARG_POINTER_REGNUM)
256 return_value += reg_size;
258 return return_value;
261 /* Called after register allocation to add any instructions needed for the
262 prologue. Using a prologue insn is favored compared to putting all of the
263 instructions in output_function_prologue(), since it allows the scheduler
264 to intermix instructions with the saves of the caller saved registers. In
265 some cases, it might be necessary to emit a barrier instruction as the last
266 insn to prevent such scheduling. */
268 void
269 fr30_expand_prologue (void)
271 int regno;
272 rtx insn;
274 if (! current_frame_info.initialised)
275 fr30_compute_frame_size (0, 0);
277 /* This cases shouldn't happen. Catch it now. */
278 gcc_assert (current_frame_info.total_size || !current_frame_info.gmask);
280 /* Allocate space for register arguments if this is a variadic function. */
281 if (current_frame_info.pretend_size)
283 int regs_to_save = current_frame_info.pretend_size / UNITS_PER_WORD;
285 /* Push argument registers into the pretend arg area. */
286 for (regno = FIRST_ARG_REGNUM + FR30_NUM_ARG_REGS; regno --, regs_to_save --;)
288 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
289 RTX_FRAME_RELATED_P (insn) = 1;
293 if (current_frame_info.gmask)
295 /* Save any needed call-saved regs. */
296 for (regno = STACK_POINTER_REGNUM; regno--;)
298 if ((current_frame_info.gmask & (1 << regno)) != 0)
300 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
301 RTX_FRAME_RELATED_P (insn) = 1;
306 /* Save return address if necessary. */
307 if (current_frame_info.save_rp)
309 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode,
310 RETURN_POINTER_REGNUM)));
311 RTX_FRAME_RELATED_P (insn) = 1;
314 /* Save old frame pointer and create new one, if necessary. */
315 if (current_frame_info.save_fp)
317 if (current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
319 int enter_size = current_frame_info.frame_size + UNITS_PER_WORD;
320 rtx pattern;
322 insn = emit_insn (gen_enter_func (GEN_INT (enter_size)));
323 RTX_FRAME_RELATED_P (insn) = 1;
325 pattern = PATTERN (insn);
327 /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
328 if (GET_CODE (pattern) == PARALLEL)
330 int x;
331 for (x = XVECLEN (pattern, 0); x--;)
333 rtx part = XVECEXP (pattern, 0, x);
335 /* One of the insns in the ENTER pattern updates the
336 frame pointer. If we do not actually need the frame
337 pointer in this function then this is a side effect
338 rather than a desired effect, so we do not mark that
339 insn as being related to the frame set up. Doing this
340 allows us to compile the crash66.C test file in the
341 G++ testsuite. */
342 if (! frame_pointer_needed
343 && GET_CODE (part) == SET
344 && SET_DEST (part) == hard_frame_pointer_rtx)
345 RTX_FRAME_RELATED_P (part) = 0;
346 else
347 RTX_FRAME_RELATED_P (part) = 1;
351 else
353 insn = emit_insn (gen_movsi_push (frame_pointer_rtx));
354 RTX_FRAME_RELATED_P (insn) = 1;
356 if (frame_pointer_needed)
358 insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
359 RTX_FRAME_RELATED_P (insn) = 1;
364 /* Allocate the stack frame. */
365 if (current_frame_info.frame_size == 0)
366 ; /* Nothing to do. */
367 else if (current_frame_info.save_fp
368 && current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
369 ; /* Nothing to do. */
370 else if (current_frame_info.frame_size <= 512)
372 insn = emit_insn (gen_add_to_stack
373 (GEN_INT (- (signed) current_frame_info.frame_size)));
374 RTX_FRAME_RELATED_P (insn) = 1;
376 else
378 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
379 insn = emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
380 RTX_FRAME_RELATED_P (insn) = 1;
381 insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
382 RTX_FRAME_RELATED_P (insn) = 1;
385 if (crtl->profile)
386 emit_insn (gen_blockage ());
389 /* Called after register allocation to add any instructions needed for the
390 epilogue. Using an epilogue insn is favored compared to putting all of the
391 instructions in output_function_epilogue(), since it allows the scheduler
392 to intermix instructions with the restores of the caller saved registers.
393 In some cases, it might be necessary to emit a barrier instruction as the
394 first insn to prevent such scheduling. */
395 void
396 fr30_expand_epilogue (void)
398 int regno;
400 /* Perform the inversion operations of the prologue. */
401 gcc_assert (current_frame_info.initialised);
403 /* Pop local variables and arguments off the stack.
404 If frame_pointer_needed is TRUE then the frame pointer register
405 has actually been used as a frame pointer, and we can recover
406 the stack pointer from it, otherwise we must unwind the stack
407 manually. */
408 if (current_frame_info.frame_size > 0)
410 if (current_frame_info.save_fp && frame_pointer_needed)
412 emit_insn (gen_leave_func ());
413 current_frame_info.save_fp = 0;
415 else if (current_frame_info.frame_size <= 508)
416 emit_insn (gen_add_to_stack
417 (GEN_INT (current_frame_info.frame_size)));
418 else
420 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
421 emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
422 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
426 if (current_frame_info.save_fp)
427 emit_insn (gen_movsi_pop (frame_pointer_rtx));
429 /* Pop all the registers that were pushed. */
430 if (current_frame_info.save_rp)
431 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, RETURN_POINTER_REGNUM)));
433 for (regno = 0; regno < STACK_POINTER_REGNUM; regno ++)
434 if (current_frame_info.gmask & (1 << regno))
435 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno)));
437 if (current_frame_info.pretend_size)
438 emit_insn (gen_add_to_stack (GEN_INT (current_frame_info.pretend_size)));
440 /* Reset state info for each function. */
441 current_frame_info = zero_frame_info;
443 emit_jump_insn (gen_return_from_func ());
446 /* Do any needed setup for a variadic function. We must create a register
447 parameter block, and then copy any anonymous arguments, plus the last
448 named argument, from registers into memory. * copying actually done in
449 fr30_expand_prologue().
451 ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
452 which has type TYPE and mode MODE, and we rely on this fact. */
453 void
454 fr30_setup_incoming_varargs (cumulative_args_t arg_regs_used_so_far_v,
455 machine_mode mode,
456 tree type ATTRIBUTE_UNUSED,
457 int *pretend_size,
458 int second_time ATTRIBUTE_UNUSED)
460 CUMULATIVE_ARGS *arg_regs_used_so_far
461 = get_cumulative_args (arg_regs_used_so_far_v);
462 int size;
464 /* All BLKmode values are passed by reference. */
465 gcc_assert (mode != BLKmode);
467 /* ??? This run-time test as well as the code inside the if
468 statement is probably unnecessary. */
469 if (targetm.calls.strict_argument_naming (arg_regs_used_so_far_v))
470 /* If TARGET_STRICT_ARGUMENT_NAMING returns true, then the last named
471 arg must not be treated as an anonymous arg. */
472 /* ??? This is a pointer increment, which makes no sense. */
473 arg_regs_used_so_far += fr30_num_arg_regs (mode, type);
475 size = FR30_NUM_ARG_REGS - (* arg_regs_used_so_far);
477 if (size <= 0)
478 return;
480 * pretend_size = (size * UNITS_PER_WORD);
483 /*}}}*/
484 /*{{{ Printing operands */
486 /* Print a memory address as an operand to reference that memory location. */
488 void
489 fr30_print_operand_address (FILE *stream, rtx address)
491 switch (GET_CODE (address))
493 case SYMBOL_REF:
494 output_addr_const (stream, address);
495 break;
497 default:
498 fprintf (stderr, "code = %x\n", GET_CODE (address));
499 debug_rtx (address);
500 output_operand_lossage ("fr30_print_operand_address: unhandled address");
501 break;
505 /* Print an operand. */
507 void
508 fr30_print_operand (FILE *file, rtx x, int code)
510 rtx x0;
512 switch (code)
514 case '#':
515 /* Output a :D if this instruction is delayed. */
516 if (dbr_sequence_length () != 0)
517 fputs (":D", file);
518 return;
520 case 'p':
521 /* Compute the register name of the second register in a hi/lo
522 register pair. */
523 if (GET_CODE (x) != REG)
524 output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
525 else
526 fprintf (file, "r%d", REGNO (x) + 1);
527 return;
529 case 'b':
530 /* Convert GCC's comparison operators into FR30 comparison codes. */
531 switch (GET_CODE (x))
533 case EQ: fprintf (file, "eq"); break;
534 case NE: fprintf (file, "ne"); break;
535 case LT: fprintf (file, "lt"); break;
536 case LE: fprintf (file, "le"); break;
537 case GT: fprintf (file, "gt"); break;
538 case GE: fprintf (file, "ge"); break;
539 case LTU: fprintf (file, "c"); break;
540 case LEU: fprintf (file, "ls"); break;
541 case GTU: fprintf (file, "hi"); break;
542 case GEU: fprintf (file, "nc"); break;
543 default:
544 output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
545 break;
547 return;
549 case 'B':
550 /* Convert GCC's comparison operators into the complimentary FR30
551 comparison codes. */
552 switch (GET_CODE (x))
554 case EQ: fprintf (file, "ne"); break;
555 case NE: fprintf (file, "eq"); break;
556 case LT: fprintf (file, "ge"); break;
557 case LE: fprintf (file, "gt"); break;
558 case GT: fprintf (file, "le"); break;
559 case GE: fprintf (file, "lt"); break;
560 case LTU: fprintf (file, "nc"); break;
561 case LEU: fprintf (file, "hi"); break;
562 case GTU: fprintf (file, "ls"); break;
563 case GEU: fprintf (file, "c"); break;
564 default:
565 output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
566 break;
568 return;
570 case 'A':
571 /* Print a signed byte value as an unsigned value. */
572 if (GET_CODE (x) != CONST_INT)
573 output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
574 else
576 HOST_WIDE_INT val;
578 val = INTVAL (x);
580 val &= 0xff;
582 fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
584 return;
586 case 'x':
587 if (GET_CODE (x) != CONST_INT
588 || INTVAL (x) < 16
589 || INTVAL (x) > 32)
590 output_operand_lossage ("fr30_print_operand: invalid %%x code");
591 else
592 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) - 16);
593 return;
595 case 'F':
596 if (GET_CODE (x) != CONST_DOUBLE)
597 output_operand_lossage ("fr30_print_operand: invalid %%F code");
598 else
600 char str[30];
602 real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x),
603 sizeof (str), 0, 1);
604 fputs (str, file);
606 return;
608 case 0:
609 /* Handled below. */
610 break;
612 default:
613 fprintf (stderr, "unknown code = %x\n", code);
614 output_operand_lossage ("fr30_print_operand: unknown code");
615 return;
618 switch (GET_CODE (x))
620 case REG:
621 fputs (reg_names [REGNO (x)], file);
622 break;
624 case MEM:
625 x0 = XEXP (x,0);
627 switch (GET_CODE (x0))
629 case REG:
630 gcc_assert ((unsigned) REGNO (x0) < ARRAY_SIZE (reg_names));
631 fprintf (file, "@%s", reg_names [REGNO (x0)]);
632 break;
634 case PLUS:
635 if (GET_CODE (XEXP (x0, 0)) != REG
636 || REGNO (XEXP (x0, 0)) < FRAME_POINTER_REGNUM
637 || REGNO (XEXP (x0, 0)) > STACK_POINTER_REGNUM
638 || GET_CODE (XEXP (x0, 1)) != CONST_INT)
640 fprintf (stderr, "bad INDEXed address:");
641 debug_rtx (x);
642 output_operand_lossage ("fr30_print_operand: unhandled MEM");
644 else if (REGNO (XEXP (x0, 0)) == FRAME_POINTER_REGNUM)
646 HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
647 if (val < -(1 << 9) || val > ((1 << 9) - 4))
649 fprintf (stderr, "frame INDEX out of range:");
650 debug_rtx (x);
651 output_operand_lossage ("fr30_print_operand: unhandled MEM");
653 fprintf (file, "@(r14, #" HOST_WIDE_INT_PRINT_DEC ")", val);
655 else
657 HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
658 if (val < 0 || val > ((1 << 6) - 4))
660 fprintf (stderr, "stack INDEX out of range:");
661 debug_rtx (x);
662 output_operand_lossage ("fr30_print_operand: unhandled MEM");
664 fprintf (file, "@(r15, #" HOST_WIDE_INT_PRINT_DEC ")", val);
666 break;
668 case SYMBOL_REF:
669 output_address (VOIDmode, x0);
670 break;
672 default:
673 fprintf (stderr, "bad MEM code = %x\n", GET_CODE (x0));
674 debug_rtx (x);
675 output_operand_lossage ("fr30_print_operand: unhandled MEM");
676 break;
678 break;
680 case CONST_DOUBLE :
681 /* We handle SFmode constants here as output_addr_const doesn't. */
682 if (GET_MODE (x) == SFmode)
684 long l;
686 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l);
687 fprintf (file, "0x%08lx", l);
688 break;
691 /* FALLTHRU */
692 /* Let output_addr_const deal with it. */
693 default:
694 output_addr_const (file, x);
695 break;
698 return;
701 /*}}}*/
703 /* Implements TARGET_FUNCTION_VALUE. */
705 static rtx
706 fr30_function_value (const_tree valtype,
707 const_tree fntype_or_decli ATTRIBUTE_UNUSED,
708 bool outgoing ATTRIBUTE_UNUSED)
710 return gen_rtx_REG (TYPE_MODE (valtype), RETURN_VALUE_REGNUM);
713 /* Implements TARGET_LIBCALL_VALUE. */
715 static rtx
716 fr30_libcall_value (machine_mode mode,
717 const_rtx fun ATTRIBUTE_UNUSED)
719 return gen_rtx_REG (mode, RETURN_VALUE_REGNUM);
722 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
724 static bool
725 fr30_function_value_regno_p (const unsigned int regno)
727 return (regno == RETURN_VALUE_REGNUM);
730 /*{{{ Function arguments */
732 /* Return true if we should pass an argument on the stack rather than
733 in registers. */
735 static bool
736 fr30_must_pass_in_stack (machine_mode mode, const_tree type)
738 if (mode == BLKmode)
739 return true;
740 if (type == NULL)
741 return false;
742 return AGGREGATE_TYPE_P (type);
745 /* Compute the number of word sized registers needed to hold a
746 function argument of mode INT_MODE and tree type TYPE. */
747 static int
748 fr30_num_arg_regs (machine_mode mode, const_tree type)
750 int size;
752 if (targetm.calls.must_pass_in_stack (mode, type))
753 return 0;
755 if (type && mode == BLKmode)
756 size = int_size_in_bytes (type);
757 else
758 size = GET_MODE_SIZE (mode);
760 return (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
763 /* Returns the number of bytes in which *part* of a parameter of machine
764 mode MODE and tree type TYPE (which may be NULL if the type is not known).
765 If the argument fits entirely in the argument registers, or entirely on
766 the stack, then 0 is returned.
767 CUM is the number of argument registers already used by earlier
768 parameters to the function. */
770 static int
771 fr30_arg_partial_bytes (cumulative_args_t cum_v, machine_mode mode,
772 tree type, bool named)
774 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
776 /* Unnamed arguments, i.e. those that are prototyped as ...
777 are always passed on the stack.
778 Also check here to see if all the argument registers are full. */
779 if (named == 0 || *cum >= FR30_NUM_ARG_REGS)
780 return 0;
782 /* Work out how many argument registers would be needed if this
783 parameter were to be passed entirely in registers. If there
784 are sufficient argument registers available (or if no registers
785 are needed because the parameter must be passed on the stack)
786 then return zero, as this parameter does not require partial
787 register, partial stack stack space. */
788 if (*cum + fr30_num_arg_regs (mode, type) <= FR30_NUM_ARG_REGS)
789 return 0;
791 return (FR30_NUM_ARG_REGS - *cum) * UNITS_PER_WORD;
794 static rtx
795 fr30_function_arg (cumulative_args_t cum_v, machine_mode mode,
796 const_tree type, bool named)
798 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
800 if (!named
801 || fr30_must_pass_in_stack (mode, type)
802 || *cum >= FR30_NUM_ARG_REGS)
803 return NULL_RTX;
804 else
805 return gen_rtx_REG (mode, *cum + FIRST_ARG_REGNUM);
808 /* A C statement (sans semicolon) to update the summarizer variable CUM to
809 advance past an argument in the argument list. The values MODE, TYPE and
810 NAMED describe that argument. Once this is done, the variable CUM is
811 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
813 This macro need not do anything if the argument in question was passed on
814 the stack. The compiler knows how to track the amount of stack space used
815 for arguments without any special help. */
816 static void
817 fr30_function_arg_advance (cumulative_args_t cum, machine_mode mode,
818 const_tree type, bool named)
820 *get_cumulative_args (cum) += named * fr30_num_arg_regs (mode, type);
823 /*}}}*/
824 /*{{{ Operand predicates */
826 #ifndef Mmode
827 #define Mmode machine_mode
828 #endif
830 /* Returns true iff all the registers in the operands array
831 are in descending or ascending order. */
833 fr30_check_multiple_regs (rtx *operands, int num_operands, int descending)
835 if (descending)
837 unsigned int prev_regno = 0;
839 while (num_operands --)
841 if (GET_CODE (operands [num_operands]) != REG)
842 return 0;
844 if (REGNO (operands [num_operands]) < prev_regno)
845 return 0;
847 prev_regno = REGNO (operands [num_operands]);
850 else
852 unsigned int prev_regno = CONDITION_CODE_REGNUM;
854 while (num_operands --)
856 if (GET_CODE (operands [num_operands]) != REG)
857 return 0;
859 if (REGNO (operands [num_operands]) > prev_regno)
860 return 0;
862 prev_regno = REGNO (operands [num_operands]);
866 return 1;
870 fr30_const_double_is_zero (rtx operand)
872 if (operand == NULL || GET_CODE (operand) != CONST_DOUBLE)
873 return 0;
875 return real_equal (CONST_DOUBLE_REAL_VALUE (operand), &dconst0);
878 /*}}}*/
879 /*{{{ Instruction Output Routines */
881 /* Output a double word move.
882 It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
883 On the FR30 we are constrained by the fact that it does not
884 support offsetable addresses, and so we have to load the
885 address of the secnd word into the second destination register
886 before we can use it. */
889 fr30_move_double (rtx * operands)
891 rtx src = operands[1];
892 rtx dest = operands[0];
893 enum rtx_code src_code = GET_CODE (src);
894 enum rtx_code dest_code = GET_CODE (dest);
895 machine_mode mode = GET_MODE (dest);
896 rtx val;
898 start_sequence ();
900 if (dest_code == REG)
902 if (src_code == REG)
904 int reverse = (REGNO (dest) == REGNO (src) + 1);
906 /* We normally copy the low-numbered register first. However, if
907 the first register of operand 0 is the same as the second register
908 of operand 1, we must copy in the opposite order. */
909 emit_insn (gen_rtx_SET (operand_subword (dest, reverse, TRUE, mode),
910 operand_subword (src, reverse, TRUE, mode)));
912 emit_insn
913 (gen_rtx_SET (operand_subword (dest, !reverse, TRUE, mode),
914 operand_subword (src, !reverse, TRUE, mode)));
916 else if (src_code == MEM)
918 rtx addr = XEXP (src, 0);
919 rtx dest0 = operand_subword (dest, 0, TRUE, mode);
920 rtx dest1 = operand_subword (dest, 1, TRUE, mode);
921 rtx new_mem;
923 gcc_assert (GET_CODE (addr) == REG);
925 /* Copy the address before clobbering it. See PR 34174. */
926 emit_insn (gen_rtx_SET (dest1, addr));
927 emit_insn (gen_rtx_SET (dest0, adjust_address (src, SImode, 0)));
928 emit_insn (gen_rtx_SET (dest1, plus_constant (SImode, dest1,
929 UNITS_PER_WORD)));
931 new_mem = gen_rtx_MEM (SImode, dest1);
932 MEM_COPY_ATTRIBUTES (new_mem, src);
934 emit_insn (gen_rtx_SET (dest1, new_mem));
936 else if (src_code == CONST_INT || src_code == CONST_DOUBLE)
938 rtx words[2];
939 split_double (src, &words[0], &words[1]);
940 emit_insn (gen_rtx_SET (operand_subword (dest, 0, TRUE, mode),
941 words[0]));
943 emit_insn (gen_rtx_SET (operand_subword (dest, 1, TRUE, mode),
944 words[1]));
947 else if (src_code == REG && dest_code == MEM)
949 rtx addr = XEXP (dest, 0);
950 rtx src0;
951 rtx src1;
953 gcc_assert (GET_CODE (addr) == REG);
955 src0 = operand_subword (src, 0, TRUE, mode);
956 src1 = operand_subword (src, 1, TRUE, mode);
958 emit_move_insn (adjust_address (dest, SImode, 0), src0);
960 if (REGNO (addr) == STACK_POINTER_REGNUM
961 || REGNO (addr) == FRAME_POINTER_REGNUM)
962 emit_insn (gen_rtx_SET (adjust_address (dest, SImode, UNITS_PER_WORD),
963 src1));
964 else
966 rtx new_mem;
967 rtx scratch_reg_r0 = gen_rtx_REG (SImode, 0);
969 /* We need a scratch register to hold the value of 'address + 4'.
970 We use r0 for this purpose. It is used for example for long
971 jumps and is already marked to not be used by normal register
972 allocation. */
973 emit_insn (gen_movsi_internal (scratch_reg_r0, addr));
974 emit_insn (gen_addsi_small_int (scratch_reg_r0, scratch_reg_r0,
975 GEN_INT (UNITS_PER_WORD)));
976 new_mem = gen_rtx_MEM (SImode, scratch_reg_r0);
977 MEM_COPY_ATTRIBUTES (new_mem, dest);
978 emit_move_insn (new_mem, src1);
979 emit_insn (gen_blockage ());
982 else
983 /* This should have been prevented by the constraints on movdi_insn. */
984 gcc_unreachable ();
986 val = get_insns ();
987 end_sequence ();
989 return val;
992 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
994 bool
995 fr30_frame_pointer_required (void)
997 return (flag_omit_frame_pointer == 0 || crtl->args.pretend_args_size > 0);
1000 /*}}}*/
1001 /*{{{ Trampoline Output Routines */
1003 /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
1004 On the FR30, the trampoline is:
1007 ldi:32 STATIC, r12
1009 ldi:32 FUNCTION, r0
1010 jmp @r0
1012 The no-ops are to guarantee that the static chain and final
1013 target are 32 bit aligned within the trampoline. That allows us to
1014 initialize those locations with simple SImode stores. The alternative
1015 would be to use HImode stores. */
1017 static void
1018 fr30_asm_trampoline_template (FILE *f)
1020 fprintf (f, "\tnop\n");
1021 fprintf (f, "\tldi:32\t#0, %s\n", reg_names [STATIC_CHAIN_REGNUM]);
1022 fprintf (f, "\tnop\n");
1023 fprintf (f, "\tldi:32\t#0, %s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
1024 fprintf (f, "\tjmp\t@%s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
1027 /* Implement TARGET_TRAMPOLINE_INIT. */
1029 static void
1030 fr30_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
1032 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
1033 rtx mem;
1035 emit_block_move (m_tramp, assemble_trampoline_template (),
1036 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
1038 mem = adjust_address (m_tramp, SImode, 4);
1039 emit_move_insn (mem, chain_value);
1040 mem = adjust_address (m_tramp, SImode, 12);
1041 emit_move_insn (mem, fnaddr);
1044 /*}}}*/
1045 /* Local Variables: */
1046 /* folded-file: t */
1047 /* End: */